-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8_StaticMethod.py
More file actions
36 lines (30 loc) · 884 Bytes
/
8_StaticMethod.py
File metadata and controls
36 lines (30 loc) · 884 Bytes
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
#C0d3 n0=9
#made By GuND0Wn151
'''
static methods can be accesed from the class without making object of the class
Therefore a static method can neither modify object state nor class state.
Static methods are restricted in what data they
can access - and they’re primarily a way to namespace your methods.
'''
class Student:
#constructor
def __init__(self,a,b,c):
self.name = a
self.age = b
self.branch = c
#isntance method
def PrintAge(self):
print(self.age)
#static methods
@staticmethod
def is18Plus(x):
return x>18
student1 = Student('ram',10,'7th')
student2 = Student('kevin',14,'9th')
"""
static methods are decorated by tag @staticmethod
"""
student1.PrintAge()
student2.PrintAge()
#accesing witht the class name Student
print(Student.is18Plus(17))