how to use parent instance variable in child class in python code example
Example: how to access parent class attribute from child class in python
class Person:
def __init__(self, fname, lname):
self.fname = fname
self.lname = lname
def display(self):
'''To check if parent method works'''
print(self.fname)
print(self.lname)
class Subscriber(Person):
def __init__(self, fname, lname, ID):
self.ID = ID
Person.__init__(self, fname, lname)
def displayID(self):
'''To see if child method works'''
print(self.ID)
John = Subscriber("John", "Doe", 1)
John.display()
John.displayID()