简体   繁体   English

python 3内置函数中的“类”是什么意思

[英]What does "class" mean in python 3 built in functions

class int(x=0)
class int(x, base=10)

Return an integer object constructed from a number or string x, or return 0 if no arguments are given.返回由数字或字符串 x 构造的整数对象,如果没有给出参数,则返回 0。 If x is a number, return x.如果 x 是数字,则返回 x。 int ().整数()。 For floating point numbers, this truncates towards zero.对于浮点数,这会向零截断。

Question

On the above paragraph, what does "class" mean?在上面的段落中,“类”是什么意思?

I think they changed them all to class instead of type我认为他们将它们全部更改为class而不是type

# Python 2
>>> int
<type 'int'>
>>> str
<type 'str'>
>>> bool
<type 'bool'>

# Python 3
>>> int
<class 'int'>
>>> str
<class 'str'>
>>> bool
<class 'bool'>

You can also check this reply您也可以查看此回复

It means the same thing as it does for all other classes, eg:它的含义与所有其他类的含义相同,例如:

class Foo: pass

it just means that it is a class.它只是意味着它是一个类。

Built-in classes are special merely because they are built-in to Python and as a result are more performant (they have some other minor quirks but that's another subject).内置类之所以特殊,仅仅是因为它们是 Python 内置的,因此性能更高(它们还有一些其他的小怪癖,但那是另一个主题)。 All in all you can treat it the same as you would your custom class that's created with a class construct.总而言之,您可以像对待使用class构造创建的自定义类一样对待它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM