Skip to content

Commit 23329bf

Browse files
committed
Completed "Classes and objects" exercises.
1 parent d1f8599 commit 23329bf

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Person:
2+
def __init__(self, name: str, age: int, preferred_operating_system: str):
3+
self.name = name
4+
self.age = age
5+
self.preferred_operating_system = preferred_operating_system
6+
7+
imran = Person("Imran", 22, "Ubuntu")
8+
print(imran.name)
9+
# print(imran.address) # error: "Person" has no attribute "address" [attr-defined]
10+
11+
eliza = Person("Eliza", 34, "Arch Linux")
12+
print(eliza.name)
13+
# print(eliza.address) # error: "Person" has no attribute "address" [attr-defined]
14+
15+
def is_adult(person: Person) -> bool:
16+
return person.age >= 18
17+
18+
print(is_adult(imran))
19+
20+
def no_attribute_exists(person: Person):
21+
print(person.dob)
22+
23+
# mypy detects that dob attribute doesn't exist.
24+
# error: "Person" has no attribute "dob" [attr-defined]

0 commit comments

Comments
 (0)