To create a class that inherits the functionality from another class, send the parent class as a parameter when creating the child class:
ExampleCreate a class named Student
, which will inherit the properties and methods from the Person
class:
class Student(Person):
pass
Note: Use the pass
keyword when you do not want to add any other properties or methods to the class.
Now the Student class has the same properties and methods as the Person class.
ExampleUse the Student
class to create an object, and then execute the printname
method:
x = Student("Mike", "Olsen")
x.printname()
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4