python - Python 2.7 中的旧式和新式类

标签 python class python-2.7 new-style-class

Possible Duplicate:
Old style and new style classes in Python

Python 2.7 中新式和旧式类的现状如何?

我不经常使用 Python,但我隐约记得这个问题。文档似乎根本没有提到这个问题:The Python Tutorial: Classes .我还需要担心这个吗?一般来说,我应该像下面这样声明我的类吗?

class MyClass:
    pass

还是?

class MyClass(object):
    pass

最佳答案

总是子类化“对象”。这些是新的样式类。

  • 这样你就可以使用 Python 3了。

  • .super() 这样的东西可以正常工作,如果你需要的话。

关于python - Python 2.7 中的旧式和新式类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13816849/

相关文章:

java - 在类之间使用变量时数学方程返回 0

c++ - 重载 << 运算符的问题

java - 为什么这个 javaclass 会得到这个异常?

python-2.7 - 检查 Pyspark Dataframe 中的重复项

python - 类型错误 : 'long' object is not iterable

Python 如何用 re.sub() 替换反斜杠

python - 值错误: Bin edges must be unique:

python 2.7 : ImportError: DLL load failed: The specified module could not be found

python - 查找特定轴上网格上最近的点(maya)

python - 如何将一列中最后一次更改的索引分配给每一行?