Skip to content

Commit 61eedd9

Browse files
explanations of method and function
1 parent 75321cd commit 61eedd9

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

sprint5-prep-exercise/methods.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from datetime import date
44

55
class 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+

0 commit comments

Comments
 (0)