What is the difference between these two code samples?
1:
class SubType(type):
def __init__(cls, name, bases, dct):
super().__init__(name, bases, dct)
2:
class SubType(type):
def __init__(cls, name, bases, dct):
pass
In python 3.x it means calling the __init__ method of the superclass (i.e. type) (as if it were a method of the current class, SubType, since the current class is a derived of the superclass).
It is the same as calling super(type, self).__init__() in Python 2.x
For example:
class type:
def __init__(self, a):
print(a)
class SubType(type):
def __init__(self, a):
super().__init__(a)
>> obj = SubType(2)
2
>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With