Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
metods.py
#python 3.5.2 #Methods classification #To process the data of object we need functions which in oops called as methods #instance method-to process instance variables #class method-to process class/static variables #staic method-to perform extra task class Student: school='ABC School'#static var def __init__(self,name,age): self.set_name(name)#instance var self.set_age(age)#instance var def set_name(self,name):#instance setter() self.name=name def get_name(self):#instance getter() return self.name def set_age(self,age): self.age=age def get_age(self): return self.age @classmethod def get_school(cls): return cls.school @staticmethod def info(): return 'Student Details\n...............' s1=Student('Ashu',23) s2=Student('Abhi',24) #print(s1.info()) #static method can be accessed using class name or object print(Student.info()) print('School :',s1.get_school())#class method can be accessed using class name or object #print(Student.get_school()) print('Name :',s1.get_name())#instance methods are accessed on object print('Age :',s1.get_age())
run
|
edit
|
history
|
help
0
Email Validation
NumPY01
linked_lists_2
chickens,cows,pigs values defined
Right_Align_Text
E
PyStack
Lesson 8!
linked_lists_2
9202335.py