forked from aluchici/cmi-portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-classes.py
More file actions
96 lines (68 loc) · 1.88 KB
/
Copy pathpython-classes.py
File metadata and controls
96 lines (68 loc) · 1.88 KB
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
90
91
92
93
94
95
class Person:
c = 1
def __init__(self, name, age, city):
self.name = name
self.age = age
self.location = city
self._secret = "secret"
self.__secret = "reaaaally secret"
def whoami(self):
print(f"I am {self.name} and I am {self.age} years old. I live in {self.location}")
def present(self):
print("Allow me to introduce myself.")
self.whoami()
def change_name(self, new_name):
self.name = new_name
self.whoami()
def tell_me_your_secret(self):
print(self.__secret, self._secret)
def __secret_method(self):
print(self.__secret)
@staticmethod
def st():
print("ss")
@classmethod
def cls_meth(cls, a):
print(cls)
class Adult(Person):
def __init__(self, name, age, city, address):
super().__init__(name, age, city)
self.address = address
class OldPerson(Adult):
def __init__(self, name, age, city, address):
super().__init__(name, age, city, address)
p1 = Person('andrei', 32, 'tgjiu')
p1.present()
p1.change_name("liviu")
p1.tell_me_your_secret()
print(p1._secret)
# print(p1.__secret)
# p1.__secret_method()
a1 = Adult('andrei', 32, 'tgjiu', 'acasa')
a1.whoami()
print(a1.address)
p2 = Person("liviu", 32, 'tgjiu')
print(f"p1.c = {p1.c}")
print(f"p2.c = {p2.c}")
Person.c += 2
print(f"p1.c = {p1.c}")
print(f"p2.c = {p2.c}")
p3 = Person("sa", 33, 'sada')
print(p3.c)
p3.c = 20
print(p3.c)
class Palindrom:
def __init__(self, s):
self.__s = s
def is_palindrom(self):
return self.__s == self.__s[::-1]
def enter_string(self, s):
self.__s = s
def get_string(self):
return self.__s
p = Palindrom('ana')
print(p.is_palindrom())
p2 = Palindrom('root')
print(p2.is_palindrom())
p.enter_string('sadas')
print(f"{p.get_string()} is palindrom = {p.is_palindrom()}")