Where is

This question already has an answer here:

  • What is the difference between old style and new style classes in Python? 9 answers
  • Python class inherits object 7 answers

  • In Python 3, if you create a class without adding a parent class it automatically inherits from object. You can't create old style classes anymore like Python 2.

    Example:

    class A: # gets defaulted to class A(object):
        pass
    

    All classes in Python3 are subclasses of object as you can see from the mro:

    >>> class A: pass
    ... 
    >>> A.__mro__
    (<class '__main__.A'>, <class 'object'>)
    

    class A(object) is still done in some Python 3 code to maintain backward compatibility with Python 2.

    链接地址: http://www.djcxy.com/p/54182.html

    上一篇: 类定义参数与普通类定义

    下一篇: 哪里