0% found this document useful (0 votes)
15 views3 pages

22 - Inheritance - Jupyter Notebook

The document is a Jupyter Notebook that demonstrates the concept of inheritance in Python through the creation of a 'Person' class and a 'Student' subclass. It shows how to initialize objects, invoke methods, and utilize the 'super()' function to access parent class attributes. The examples include printing names and welcoming students with their graduation year.

Uploaded by

nmdrafiqj2003
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)
15 views3 pages

22 - Inheritance - Jupyter Notebook

The document is a Jupyter Notebook that demonstrates the concept of inheritance in Python through the creation of a 'Person' class and a 'Student' subclass. It shows how to initialize objects, invoke methods, and utilize the 'super()' function to access parent class attributes. The examples include printing names and welcoming students with their graduation year.

Uploaded by

nmdrafiqj2003
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

30/08/2023, 19:30 _22_inheritance - Jupyter Notebook

In [ ]:

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):
pass

x = Student("Mike", "Olsen")
[Link]()

In [1]:

class Person:
def __init__(self, fname, lname):
[Link] = fname
[Link] = lname

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

class Student(Person):
def __init__(self, fname, lname):
Person.__init__(self, fname, lname)

x=Student("rajasekar","rk")
[Link]()

rajasekar rk

localhost:8888/notebooks/OneDrive/_04_python_class_notes___/_22_inheritance.ipynb 1/3
30/08/2023, 19:30 _22_inheritance - Jupyter Notebook

In [2]:

class Person:
def __init__(self, fname, lname):
[Link] = fname
[Link] = lname

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

class Student(Person):
def __init__(self, fname, lname):
super().__init__(fname, lname)

x=Student("rajasekar","rk")
[Link]()

rajasekar rk

In [4]:

class Person:
def __init__(self, fname, lname):
[Link] = fname
[Link] = lname

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

class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
[Link] = year

x = Student("Mike", "Olsen", 2019)


[Link]()

Mike Olsen 2019

In [5]:

class Person:
def __init__(self, fname, lname):
[Link] = fname
[Link] = lname

class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
[Link] = year

def welcome(self):
print("Welcome", [Link], [Link], "to the class of", [Link]

x = Student("Mike", "Olsen", 2019)


[Link]()

Welcome Mike Olsen to the class of 2019

localhost:8888/notebooks/OneDrive/_04_python_class_notes___/_22_inheritance.ipynb 2/3
30/08/2023, 19:30 _22_inheritance - Jupyter Notebook

In [ ]:

In [ ]:

In [ ]:

localhost:8888/notebooks/OneDrive/_04_python_class_notes___/_22_inheritance.ipynb 3/3

You might also like