-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamply.py
More file actions
71 lines (56 loc) · 1.51 KB
/
examply.py
File metadata and controls
71 lines (56 loc) · 1.51 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
def avr(first, *rest):
return (first + sum(rest)) / 1 + len(rest)
print(avr(10,400,4531,45231))
def norm(a, b="Hello"):
print(a, b)
norm("great")
norm("hi", "everyone")
norm("")
# single method class
# class usage
_formats = {
'ymd': '{d.year}-{d.month}-{d.day}',
'mdy': '{d.month}/{d.day}/{d.year}',
'dmy': '{d.day}/{d.month}/{d.year}'
}
class Date:
def __init__(self, year, month, day):
self.year = year
self.month = month
self.day = day
def __format__(self, code):
if code=='':
code = 'ymd'
fmt = _formats[code]
return fmt.format(d=self)
d = Date(2019,12,10)
print(format(d, 'dmy'))
class Calculate:
def __init__(self, a, b):
self.a = a
self.b = b
@property
def _height(self):
return self.a*self.b
@property
def _volume(self):
return self.a*self.a + self.b*self.b
@property
def _sum(self):
return self.a+self.b
@property
def _subt(self):
return self.a-self.b
n = Calculate(100,20)
print("This is height ", n._height, "this is vol ", n._volume, "this is sum ", n._sum, "this is subt ", n._subt)
class Name:
def __init__(self, firstname, lastname):
self.firstname = firstname
self.lastname = lastname
def godName(self):
print("Hey" + "\n" + "your god name is Luck " + self.firstname )
def goodName(self):
print("Your good name is Buddy " + self.lastname)
n = Name("enjoy", "holiday")
n.godName()
n.goodName()