How do you inherit one class from another class in Python?
Experience Level: Junior
Tags: Python
Answer
To inherit one class from another, define a new class and add the class name of the class to inherit from between brackets after the first class name.
Example:
class Parent:
def do_something():
print("Called do_something()")
class Child(Parent):
def do_something_else():
print("Called do_something()")
value = Child()
value.do_something()
value.do_something_else()
Related Python job interview questions
What is bool data type good for in Python?
Python JuniorWhat is a Set data type good for in Python?
Python JuniorWhy would you want to inherit a class for another class in Python?
Python JuniorWhat does strftime stand for in Python?
Python JuniorWhat does strptime stand for?
Python Junior
Chat
Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.
Anonymous
Καλησπέρα.
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
the infinteis -3/15 so 1triition / infinet
Anonymous
e
e
Anonymous
<a href="https://inspirum.pl "
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
[url]https://inspirum.pl[/url]
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e