Class definition parameter vs. Normal class definition

This question already has an answer here:

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

  • In Python 2, the former is a "new-style class" and the latter is an "old-style class" that only exists for backwards compatibility. You should never use the latter for anything new.

    In Python 3, I believe there is no difference at all. You can even leave out the parentheses entirely.


    In two words:

    # new style
    class Car(object):
        pass
    

    A "New Class" is the recommended way to create a class in modern Python.

    # classic style
    class Car():
        pass
    

    A "Classic Class" or "old-style class" is a class as it existed in Python 2.1 and before. They have been retained for backwards compatibility. This page attempts to list the differences.

    Please look at:

  • http://python-history.blogspot.com/2010/06/new-style-classes.html
  • https://wiki.python.org/moin/NewClassVsClassicClass
  • https://www.python.org/doc/newstyle/
  • 链接地址: http://www.djcxy.com/p/54184.html

    上一篇: Python类定义(对象)

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