-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path9_ClassMethod.py
38 lines (30 loc) · 928 Bytes
/
9_ClassMethod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#C0d3 n0=9
#made By GuND0Wn151
'''
A class method is a method that
is bound to a class rather than its object.
It doesn't require creation of a class instance, much like staticmethod.
'''
class Student:
#constructor
age=0
def __init__(self,a,b,c):
self.name = a
self.age = b
self.branch = c
#isntance method
def PrintAge(self):
print(self.age)
'''
The difference between a static method and a class method is:
-- > Static method knows nothing about the class and just deals with the parameters
-- > Class method works with the class since its parameter is always the class itself.
'''
@classmethod
def ClassMethod(cls,name):
print(name)
student1 = Student('ram',10,'7th')
student2 = Student('kevin',14,'9th')
student1.PrintAge()
student2.PrintAge()
Student.ClassMethod("hello")