Python super()

Configurare noua (How To)

Situatie

The super() builtin returns a proxy object (temporary object of the superclass) that allows us to access methods of the base class.

Solutie

Pasi de urmat

class Mammal(object):
def __init__(self, mammalName):
print(mammalName, ‘is a warm-blooded animal.’)

class Dog(Mammal):
def __init__(self):
print(‘Dog has four legs.’)
super().__init__(‘Dog’)

d1 = Dog()

Output:

Dog has four legs.
Dog is a warm-blooded animal.

Tip solutie

Permanent

Voteaza

(7 din 15 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?