Name | super |
||
---|---|---|---|
Examples |
class Robot(object): def speak(self): print("BZZT BOOP BEEP") class RoboFeline(Robot): def speak(self): super(RoboFeline, self).speak() print("MEOW PURR PURR") kitty = RoboFeline() kitty.speak() # Prints: # BZZT BOOP BEEP # MEOW PURR PURR class Animal(object): def __init__(self): self.leg_count = 6 class Grasshopper(Animal): def __init__(self): # call the __init__ method of parent class super(Grasshopper, self).__init__() hopsalot = Grasshopper() print(hopsalot.leg_count) # Prints 6 | ||
Description | The super() function allows you to call a method defined in a parent class. Invoke the function with two parameters: the name of the class the method is defined in, and self. See the official Python documentation for more details. | ||
Syntax | super(class, self) | ||
Parameters |
| ||
Related |
class |
Updated on Mon Sep 21 15:53:25 2020.
If you see any errors or have comments, please let us know.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License