You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/042-understanding_classes/README.md
+5-6Lines changed: 5 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -14,17 +14,16 @@ class Student:
14
14
self.grade = grade
15
15
16
16
defintroduce(self): # This is a method
17
-
print(f"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}.")
17
+
returnf"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}."
18
18
19
19
defstudy(self, hours): # This is another method
20
-
print(f"{self.name} is studying for {hours} hours.")
21
20
self.grade += hours *0.5
22
-
print(f"After studying, {self.name}'s new grade is {self.grade}.")
21
+
returnf"After studying for {hours} hours, {self.name}'s new grade is {self.grade}."
23
22
24
23
student1 = Student("Ana", 20, 80)
25
24
26
-
student1.introduce()
27
-
student1.study(3)
25
+
print(student1.introduce())
26
+
print(student1.study(3))
28
27
```
29
28
30
29
In this code:
@@ -41,4 +40,4 @@ In this code:
41
40
42
41
+ Read about the `__init__` built-in function: https://www.w3schools.com/python/gloss_python_class_init.asp
43
42
44
-
+ If you find yourself wondering about the role of the `self` keyword in Python classes, take a moment to visit the following link for a detailed explanation: [Understanding the 'self' Parameter](https://www.geeksforgeeks.org/self-in-python-class/)
43
+
+ If you find yourself wondering about the role of the `self` keyword in Python classes, take a moment to visit the following link for a detailed explanation: [Understanding the 'self' Parameter](https://www.geeksforgeeks.org/self-in-python-class/)
0 commit comments