how to inherit a class in python

Solutions on MaxInterview for how to inherit a class in python by the best coders in the world

showing results for - "how to inherit a class in python"
Elia
15 Jul 2019
1class awwab(object):
2    def __init__(self, name, age):
3        self.name = name
4        self.age = age
5    
6    def speak(self):
7        print("Hello, my name is",self.name,"and I am",self.age,"years old!")
8        
9awwabasad = awwab("Awwab Asad", 11)
10print(awwabasad.speak())
11
12class naail(awwab):
13    def __init(self, name, age):
14        super().__init__(self, name, age)
15    
16naailasad = naail("Naail Asad", 8)
17print(naailasad.speak())
Olivia
19 Sep 2017
1class Bird():
2        def eat(self):
3                print ("eating")
4 
5class Sparrow(Bird):
6        def sound(self):
7                print ("ChiChi!")
8 
9birdobj = Sparrow()
10birdobj.eat()
11birdobj.sound()