pythonunit5
pythonunit5
self.address =input("Enter
Address : ")
def printStudentDetails(self):
print(self.rollno,self.name,
self.address)
S1=Student
()
S1.getStud
entDetails()
print("Stud
ent Details
")
S1.printStu
dentDetails
() Output:
Enter Roll
Number :
001 Enter
Name :
ABC
Enter Address :
New York Student
Details :
001 ABC New York
(Any suitable program can consider)
#parent class
Class Animal:
#properties
multicellular = True
# Eukaryotic means Cells with
Nucleus eukaryotic = True
# functionbreath
Def breathe(self):
Print(“I breath oxygen”)
#function feed
Def feed(self):
Print (“I eat food”)
# function feed
def feed(self):
print("I eat only plants. I am vegetarian.")
herbi = Herbivorous()
#child class
Class Herbivorous(Animal):
herbi.feed()
#calling some other function
Herbi.breathe()
Output:
I eat only plants.iam vegetarian.
I breath oxygen
When two or more methods in the same class have the same method
name but different parameters, this is called overloading.
In contrast, overriding occurs when two methods have the same name and
parameters.
You can use Overloading and Overriding more effectively now that you
understand the distinction between the two
return a + b
return a - b
return a * b
return a / b
# main.py
import calculator
class Person(object):
# Constructor
# To get name
def getName(self):
return self.name
output
Output:
Geek1 False
Geek2 True
i Write a program to create class students with roll no and name and 2M
display its contents
# Create class Student
class Student:
self.name = name
self.roll = roll
self.s1 = s1
self.s2 = s2
ls.append(obj)
print("\n")
# Search Function
for i in range(ls.__len__()):
if (ls[i].roll == rn):
return i
i = obj.search(rn)
del ls[i]
# Update Function
i = obj.search(rn)
rolln = No
ls[i].roll = rolln;
ls = []
# Object of class
obj1 = Student('', 0, 0, 0)
print("\n")
print("\nList of Students\n")
for i in range(ls.__len__()):
obj1.display(ls[i])
s = obj1.search(2)
obj1.display(ls[s])
obj1.delete(2)
print(ls.__len__())
for i in range(ls.__len__()):
obj1.display(ls[i])
obj1.update(3, 2)
for i in range(ls.__len__()):
obj1.display(ls[i])
self.name = name
self.age = age
def __str__(self):
return f"{self.name}({self.age})"
p1 = Person("John", 36)