how to use parent methods in child class 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()