-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass & Method "Function"
64 lines (48 loc) · 1.95 KB
/
Class & Method "Function"
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
class Demo_Class : # This is a Class
def demo_method(self): # this is a method within the Class
print("This is a demonstration Class") # a command in this Class
###############################################
###############################################
my_object = Demo_Class() # We Use The Class By Instance = Class()
my_object.demo_method() # Instance.method()
###############################################
###############################################
class DoubleIt: # Class
def Method (self, x, y): # Function
doubled_value = (x*y)
return doubled_value
my_object = DoubleIt() # first method to use Class+Function
print(my_object.Method(11, 10))
print(DoubleIt.Method(0, 11, 10)) # Second Method to use Class+Function
###############################################
###############################################
Result :
110
110
###############################################
###############################################
Class & Function & Return exemple :
class AddingNumbers :
def AddMethod(self,add1,add2):
add1=input ("Enter Value X : ")
add2 = input ("Enter Value Y : ")
add = int(add1)+int(add2)
return add
operation1 = AddingNumbers
print("Result of Operation 1 is = ", operation1.AddMethod(operation1,add1=0, add2=0))
operation2 = AddingNumbers
print("Result of Operation 2 is = ", operation2.AddMethod(operation2, add1=0, add2=0))
operation3 = AddingNumbers
print("Result of Operation 3 is = ", operation3.AddMethod(operation3,add1=0, add2=0))
###############################################
###############################################
Result :
Enter Value X : 10
Enter Value Y : 5
Result of Operation 1 is = 15
Enter Value X : 12
Enter Value Y : 1
Result of Operation 2 is = 13
Enter Value X : 13
Enter Value Y : 31
Result of Operation 3 is = 44