forked from Vitaliyzhiv/Python-Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOOP_practice.py
89 lines (61 loc) · 1.41 KB
/
OOP_practice.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def foo(x, y): # что возращает эта функция
return x + y
# print(foo(32,41))
# print(foo('32','41'))
# print(foo([32],[41]))
class Animal():#
legs = 4
tail = 1
name = "Неизвестное животное"
def voice(self):
return 'Some voice'
class Dog(Animal):
name = "Собака"
def voice(self):
return 'Bark-Bark'
class Cat(Animal):
name = "Кошка"
def voice(self):
return 'Mew-Mew'
class Cow(Animal):
name = "Корова"
def voice(self):
return 'Moo-Moo'
cat = Cat()
dog = Dog()
cow = Cow()
animal = Animal()
band = [cat, dog, cow, animal]
# for i in band:
# print()
# print(f'У {i.name} {i.legs} ноги и {i.tail} хвост\n'
# f'{i.name} говорит {i.voice()}')
# print(i.voice())
"""
Датаклассы
"""
from dataclasses import dataclass, asdict
@dataclass
class User:
name: str
age: int
# a = User('asd',123)
# assert asdict(a) == {'name':'asd','age': 123}
# print(a)
class UserHandle:
def __init__(self, name, age):
self.user = User(name, age)
def get_dataclass(self):
return asdict(self.user)
def edit(self, key, value):
self.user.__dict__[key] = value
n = 234
match n:
case 0:
print('first')
case 1:
print('second')
case 2:
print('third')
case _:
print('default')