Simple example of Inheritance in Python
Inheritance can be achieve by passing the parent class as an argument in the class definition of child class.
# Parent class created class Parent: parentname = "" childname = "" def show_parent(self): print(self.parentname) # Child class created inherits Parent class class Child(Parent): def show_child(self): print(self.childname) ch1 = Child() # Object of Child class ch1.parentname = "Mark" # Access Parent class attributes ch1.childname = "John" ch1.show_parent() # Access Parent class method ch1.show_child() # Access Child class method
2019-01-08T15:50:38+05:30
2019-01-08T15:50:38+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution