【问题标题】:What does "class" mean in python 3 built in functionspython 3内置函数中的“类”是什么意思
【发布时间】:2017-02-01 10:58:14
【问题描述】:
class int(x=0)
class int(x, base=10)

返回一个由数字或字符串 x 构造的整数对象,如果没有给出参数,则返回 0。如果 x 是数字,则返回 x.int()。对于浮点数,这将截断为零。

问题

上一段中,“类”是什么意思?

【问题讨论】:

  • “class”一词在代码中,但不在段落中。你的目标到底是什么?试图更好地理解一些事情?因为这有点像家庭作业问题?

标签: python python-3.x class


【解决方案1】:

我认为他们将它们全部更改为 class 而不是 type

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

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

您也可以查看this reply

【讨论】:

    【解决方案2】:

    它与所有其他类的含义相同,例如:

    class Foo: pass
    

    它只是意味着它是一个类。

    内置类之所以特殊,仅仅是因为它们是 Python 内置的,因此性能更高(它们还有一些其他的小怪癖,但这是另一个主题)。总而言之,您可以像对待使用 class 构造创建的自定义类一样对待它。

    【讨论】:

      猜你喜欢
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      相关资源
      最近更新 更多