FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tutorials/core-python/Core_Python/oop/TypesOfMethods.py at master · deepdalsania/tutorials · GitHub
deepdalsania
/
tutorials
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
8
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tutorials
/
core-python
/
Core_Python
/
oop
/
TypesOfMethods.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (31 loc) · 1.42 KB
Breadcrumbs
tutorials
/
core-python
/
Core_Python
/
oop
/
TypesOfMethods.py
Copy path
File metadata and controls
42 lines (31 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
39
40
41
42
class
Student
:
college
=
'NGI'
def
__init__
(
self
,
m1
,
m2
,
m3
):
self
.
m1
=
m1
self
.
m2
=
m2
self
.
m3
=
m3
# this is an instance method it has 2 types accessor and mutator
def
findAvg
(
self
):
return
(
self
.
m1
+
self
.
m2
+
self
.
m3
)
/
3
'''# this is an accessor : it dosen't change value just fetch the values
def get_m1(self):
return self.m1
# this is a mutator : it used for changing the value
def set_m1(self ,m1):
self.m1 = m1 '''
'''this is a class method if we are not annotating then it will give an error so we have to use decorators
for the class method we can't use self because it is for instance method so we have to pass cls for class methods'''
@
classmethod
def
getCollege
(
cls
):
return
cls
.
college
''' this is a static method which is not concerning with class or instance variables and we have to use @staticmethod decorators
for this and we can use this for finding a factorial because it isn't concern with any variables'''
@
staticmethod
def
info
():
return
"This is Static Method"
s1
=
Student
(
89
,
85
,
87
)
s2
=
Student
(
74
,
75
,
79
)
print
(
"Average for first student using instance method : "
,
s1
.
findAvg
())
print
(
"Average for second student using instance method : "
,
s2
.
findAvg
())
print
(
"Student Information using class method : "
,
Student
.
getCollege
())
print
(
"Static Method calling : "
,
Student
.
info
())
Back
|
FazBrowse Home
|
New Git URL