0% found this document useful (0 votes)
3 views1 page

Python Ass

The document presents a Python program defining a class hierarchy with a base class 'person' and two derived classes 'teacher' and 'student'. It creates instances of 'teacher' and 'student', demonstrating their specific methods and attributes. The output includes the age and gender of the instances and the respective actions of teaching and studying.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Python Ass

The document presents a Python program defining a class hierarchy with a base class 'person' and two derived classes 'teacher' and 'student'. It creates instances of 'teacher' and 'student', demonstrating their specific methods and attributes. The output includes the age and gender of the instances and the respective actions of teaching and studying.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Programme :

class person:
def __init__(self, age, gender):
self.age = age
self.gender = gender
class teacher(person):
def teaches(self):
print("I am teacher")

class student(person):
def studies(self):
print("I study")

teacher1 = teacher(40, "male")


student1 = student(20, "female")

teach = person('40', 'male')


stud = person('20', 'female')
print(teach.age, teach.gender)
teacher1.teaches()
print(stud.age,
stud.gender)
student1.studies()

Output :

You might also like