-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.py
More file actions
63 lines (54 loc) · 1.53 KB
/
decorator.py
File metadata and controls
63 lines (54 loc) · 1.53 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
import random
def decor (func): #decorators
def wrap():
print('************')
func()
print('************')
return wrap
def print_text():
print('hello')
decorated=decor(print_text)
decorated()
class student: #magic methods
def __init__(self,cont):
self.cont=cont
def __truediv__(self,other):
line ='=' *len(other.cont)
return '\n'.join([self.cont,line,other.cont])
contenu=student('hello python')
contenu_2=student('how are you ?')
print(contenu/contenu_2)
class Vector2d:
def __init__(self,x,y):
self.x=x
self.y=y
def __add__(self,other):
return Vector2d(self.x+other.x,self.y+other.y)
first=Vector2d(5,7)
second=Vector2d(3,9)
result=first+second
print(result.x)
print(result.y)
class specialstring:
def __init__(self,cont):
self.cont=cont
def __gt__(self,other):
for index in range(len(other.cont)+1):
result=other.cont[:index]+">"+self.cont
result += ">" + other.cont[index:]
print(result)
python=specialstring("python")
hello=specialstring("hello")
python>hello
class Vaguelist:
def __init__(self,cont):
self.cont=cont
def __getitem__(self,index):
return self.cont[index+random.randint(-1,1)]
def __len__(self):
return random.randint(0,len(self.cont)*2)
vague_list=Vaguelist(["A","B","C","D","E"])
print(len(vague_list))
print(len(vague_list))
print(vague_list[2])
print(vague_list[2])