【问题标题】:is there a difference between class(): and class(object): in python 2.6-3.x?在 python 2.6-3.x 中,class(): 和 class(object): 之间有区别吗?
【发布时间】:2011-03-23 18:41:53
【问题描述】:

在 py2.6 之前已在此处回答。 Difference between class foo and class foo(object) in Python

但是对于python2.6+和python3.x,第一个错了吗?

class Foo(): passclass Foo(object): pass

【问题讨论】:

    标签: class object python-2.6 python-3.x


    【解决方案1】:

    对于 Python2.6+,在 Python 3.0 之前,前者创建一个旧式类,而后者创建一个新式类。在 Python 3.0 中,两者都创建了新样式。第一个没有错,但对于 3.0 之前的任何内容,它的语义与后者不同,通常不鼓励使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 2021-09-23
      • 2011-06-09
      • 2016-10-04
      • 1970-01-01
      相关资源
      最近更新 更多