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
classThe class in which the method is defined
Related class

Updated on Tue Feb 27 14:07:12 2024.

If you see any errors or have comments, please let us know.