I am making a class in Python, as shown:
class BaseClass:
def __init__(self, number):
self.number = number
self.id = "Class Base"
def behavior(self, person):
print("Hello,", person)
Now I want to use this class as a base. I am creating a new class called SubClass
which has its self.id
set to Subclass
, and a new function called add
.
I could simply type this:
class SubClass:
def __init__(self, number):
self.number = number
self.id = "Subclass"
def behavior(self, person):
print("Hello,", person)
def add(self, one, two):
return one + two
But I was wondering if I could do this like you can in Java, where you could type class SubClass extends BaseClass
.
Is this possible in Python? I am specifically looking for Python 3.x, but any version should work.