-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_1.py
More file actions
36 lines (27 loc) · 768 Bytes
/
OOP_1.py
File metadata and controls
36 lines (27 loc) · 768 Bytes
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
33
34
35
36
# class
class Person:
# class attributes
adress = 'no information'
# constructor
def __init__(self, name, year):
# object attributes
self.name = name
self.year = year
# print('init metot')
# instance methods
def intro(self):
print('Hello. I am '+ self.name)
# instance methods
def calculateAge(self):
return 2022 - self.year
# object (instance)
p1 = Person(name='Alex', year=200)
p2 = Person(name='Ali', year=2005)
p1.intro()
p2.intro()
print(f'I am {p1.calculateAge()} years old')
# updating
# p1.name = 'Akar'
# accessing object attributes
# print(f'p1 :name: {p1.name} year: {p1.year} adress : {p1.adress}')
# print(f'p1 :name: {p2.name} year: {p2.year} adress : {p2.adress}')