File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from datetime import date
44
55class Person :
6+ # __init__ is a method (a function inside a class)
67 def __init__ (self , name : str , dob : date , preferred_operating_system : str ):
78 self .name = name
89 self .dob = dob
910 self .preferred_operating_system = preferred_operating_system
1011
12+ # is_adult is also a method
1113 def is_adult (self ) -> bool :
1214 today = date .today ()
1315
@@ -17,4 +19,15 @@ def is_adult(self) -> bool:
1719 if (today .month , today .day ) < (self .dob .month , self .dob .day ):
1820 age -= 1
1921
20- return age >= 18
22+ return age >= 18
23+
24+
25+ # Function:
26+ # A reusable block of code that exists independently.
27+ # This is a normal function:
28+ # def greet():
29+ # print("Hello")
30+
31+ # Method:
32+ # A function that belongs to a class and usually works with object data using `self`.
33+
You can’t perform that action at this time.
0 commit comments