-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic_Method.py
More file actions
69 lines (50 loc) · 1.24 KB
/
Copy pathStatic_Method.py
File metadata and controls
69 lines (50 loc) · 1.24 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
""" _______________________________ """
#!""" Static Method """
class Math:
@staticmethod
def add(x,y):
return x+y
@staticmethod
def add5(num):
return num+5
@staticmethod
def add10(num):
return num+10
@staticmethod
def PI():
return 3.14
x = Math.add(5,10)
y = Math.add5(x)
z = Math.add10(y)
print(x,y,z) #* The output is 15 20 30
class Pizza:
def __init__(self, radius, ingredients):
self.__radius = radius
self.__ingredients=ingredients
def __str__(self):
return f"Pizza ingredients are {self.__ingredients}"
def area(self):
return Pizza.circle_area(self.__radius)
@staticmethod
def circle_area(r):
return r**2 * Math.PI()
pizza_1 = Pizza(6,['Mozzarella','Tomatoes'])
print(pizza_1.area()) #* The output is 113.04
print(Pizza.circle_area(4)) #* The output is 50.24
class Dates:
def __init__(self,date):
self.__date = date
def getDate(self):
return self.__date
@staticmethod
def toDashDate(date):
return date.replace("/","-")
date = Dates("15-12-2016")
dateFromDB = "15/12/2016"
dateWithDash = Dates.toDashDate(dateFromDB)
if(date.getDate()==dateWithDash):
print("Equal")
else:
print("Unequal")
#* The output is Equal
""" _______________________________ """