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

Oops 1 20

The document presents a Python demo program that defines a Student class with methods to set and get student names and marks. It includes a loop to input multiple students' details and display them. Additionally, it explains the concept of class methods and how to declare them using the @classmethod decorator.

Uploaded by

vishnu050621
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)
5 views1 page

Oops 1 20

The document presents a Python demo program that defines a Student class with methods to set and get student names and marks. It includes a loop to input multiple students' details and display them. Additionally, it explains the concept of class methods and how to declare them using the @classmethod decorator.

Uploaded by

vishnu050621
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

Demo Program:

1) class Student:
2) def setName(self,name):
3) self.name=name
4)
5) def getName(self):
6) return self.name
7)
8) def setMarks(self,marks):
9) self.marks=marks
10)
11) def getMarks(self):
12) return self.marks
13)
14) n=int(input('Enter number of students:'))
15) for i in range(n):
16) s=Student()
17) name=input('Enter Name:')
18) s.setName(name)
19) marks=int(input('Enter Marks:'))
20) s.setMarks(marks)
21)
22) print('Hi',s.getName())
23) print('Your Marks are:',s.getMarks())
24) print()

output:
D:\python_classes>py test.py
Enter number of students:2
Enter Name:Durga
Enter Marks:100
Hi Durga
Your Marks are: 100

Enter Name:Ravi
Enter Marks:80
Hi Ravi
Your Marks are: 80

2. Class Methods:
Inside method implementation if we are using only class variables (static variables), then such type
of methods we should declare as class method.

We can declare class method explicitly by using @classmethod decorator.


For class method we should provide cls variable at the time of declaration

nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
20  040 – 64 51 27 86, 80 96 96 96 96, 92 46 21 21 43 | www.durgasoft.com

You might also like