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

Python Class Inheritance Example

The document defines a Person class with methods to initialize and print a person's name. It also defines a Student class that inherits from Person and adds a graduation year attribute. Instances of both classes are created, and their methods are demonstrated, although some parts of the code are commented out.

Uploaded by

jahnavijoshi365
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Python Class Inheritance Example

The document defines a Person class with methods to initialize and print a person's name. It also defines a Student class that inherits from Person and adds a graduation year attribute. Instances of both classes are created, and their methods are demonstrated, although some parts of the code are commented out.

Uploaded by

jahnavijoshi365
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

class Person:

def __init__(self, fname, lname):


[Link] = fname
[Link] = lname
def printname(self):
print([Link], [Link])
#Use the Person class to create an object, and then execute the printname method:
x = Person("John", "Doe")
[Link]()
class Student(Person):
def __init__(self, fname, lname,gyear):
[Link] = fname
[Link] = lname
#Person.__init__(self, fname, lname)
#super().__init__(fname, lname)
[Link] = gyear

"""
def printname(self):
print([Link], [Link],[Link])
"""

y = Student("Shyam", "Singhal",2018)
[Link]()
#print([Link])
z=Person("John","Sharma")
print([Link]())

You might also like