Difference between class declarations

前端 未结 3 879
一向
一向 2021-01-20 21:20

I see some similar questions about this topic, but i wish to be sure, so i am asking...

What is the difference between:

class MyClass:
    pass
         


        
3条回答
  •  礼貌的吻别
    2021-01-20 21:56

    There is no difference between class MyClass and class MyClass(). The second question is dependent on your python version. On python3.x, there is no difference -- On python2.x, the latter (where you inherit from object) creates a new-style class rather than an old-style class. In python3.x, ALL classes are new-style. New style classes are preferred these days -- As such, I always make sure that my classes inherit from object.

提交回复
热议问题