-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoop_abstractions.py
38 lines (24 loc) · 920 Bytes
/
oop_abstractions.py
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
37
38
# hiding info and giving necessary access
# abstract how its implemented
# public and private access
# prevent modification from user
print((1,2,3,2,1).count(2))
class PlayerCharacter:
# calls every time instantiate
# __ means dunder method built in method
def __init__(self, name='anonymous', age=0):
self._name = name # private variable
self._age = age
def run(self):
print(f'my name is {self._name}, and age is {self._age}')
def speak(self): # encapsulation
print(f'my name is {self._name}, and age is {self._age}')
def __abstractTest(self): # encapsulation
print(f'my name is {self._name}, and age is {self._age}')
player1 = PlayerCharacter(name='Tom', age=10)
player1.speak = 'change'
player1._name = 'name changes'
print(player1._name)
player1.__abstractTest = 'cant change'
print(player1.speak)
print(player1._abstractTest)