-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.py
More file actions
63 lines (54 loc) · 1.24 KB
/
functions.py
File metadata and controls
63 lines (54 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
#Functions
#basic func
def myfunc():
print('Hello World')
#function with arguments
def add(a,b):
print(a+b)
#function return values
def square(x):
return x*x
#function with default value of argument
def mult(a,b=5):
print(a*b)
def subtract(a,b=3):
print(a - b)
#function with variable number of arguments
def multiadd(*args):
result = 0
for x in args:
result = result + x
return result
#different way access
myfunc()
print(myfunc)
print(myfunc())
myfunc
#print(add(10,4)) #This print None Because it print itself in function
add(10,4)
sq =square(10)
print(sq)
#it takes one args and another process with default value.
mult(5)
mult(3,5)
#if you give two argument then it use those otherwise by default values used likw above
mult(10,4)
#mult(z=10,v=8) #this is not work
mult(b=1,a=2)
print('subtract: ',end=" ")
subtract(b=5,a=2)
print('Function With MultiArguments: ')
#function with multiArguments
res = multiadd(1)
print(res)
res1 =multiadd(1,2)
print(res1)
res2 =multiadd(1,2,3,4)
print(res2)
#Note: Python Execute Program using Top Down Aproach
#So this is not work
#NameError: name 'printHello' is not defined
#if __name__ == "__main__":
# printHello()
#def printHello():
# print("Hello World")