There is no difference between them in terms of what classes they define.
If you read Python 3's grammar definition, you can see that this parenthesis is optional in class definitions.You can also write a list of classes from which to inherit the classes you want to define, but if you omit the inheritance source, it also says that object
class will be the inheritance source.
Therefore, omit the parentheses
class C:
pass
Even if you write it, write it in parentheses
class C():
pass
Even if you write that, both of them are the same
class C(object):
pass
The class is defined in the same way as the .
In fact, if you try the behavior in the interpreter, you will see that you define a class that inherits only the object
class:
>>class C1:
... pass
...
>> Class C2:
... pass
...
>>>C1.__mro__
(<class'___main__.C1'>, <class' object'>)
>> C2.__mro__
(<class '__main__.C2'>, <class 'object'>)
© 2024 OneMinuteCode. All rights reserved.