forked from vandanagarg/practice_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction in classes
More file actions
33 lines (22 loc) · 1.15 KB
/
function in classes
File metadata and controls
33 lines (22 loc) · 1.15 KB
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
#Object Functions #function in classes
#class functions is something that can be used within the class and can be used to modify objects of that class
from student import Student
student1 = Student("van", "Maths", 3.8)
student2 = Student("PS", "science", 3.1)
print(student2.on_honor_roll())
##module student.py
class Student: #buiding attributes for student class
#def __init__(self, name, major, gpa, is_on_probation): # this init function is describing what a student has, like how we want to describe a student
def __init__(self, name, major, gpa): #this init function is describing what a student has, like how we want to describe a student
self.name = name
self.major = major
self.gpa = gpa
# self.is_on_probation = is_on_probation
def on_honor_roll(self): #for object function we just add a small function in here
if self.gpa >= 3.5:
return True
else:
return False
#class is basically an overview of what student datatype is
#and an object is an actual student represented inside our programm and is no more a
#now we have to call this filefrom our actual file/programm