-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.py
86 lines (42 loc) · 1.33 KB
/
functions.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#Python Functions Tasks
#1. Create a simple function that takes 2 numbers and print their values
def mysum(x,y):
print(x)
print (y)
mysum(5,6)
#2. Create a simple function that takes 2 numbers and return their values
def mysum(x,y):
return x
return y
l = mysum(5,6)
print(l)
#3. In the above return function, use keyword arguments when calling the function
def mysum(x,y):
return x+y
l = mysum(x=2,y=3)
print(l)
#4. In the above return function, give x and y default values of O and call the function with no arguments
def mysum(x =0,y=0):
return x+y
l = mysum()
print(l)
#5. Create a function that can take any number of arguments and print the sum of them
def mysum(arg,*vartuple):
result = arg + sum(vartuple)
return result
l = mysum(1,2,3,4,5,6)
print(l)
#6. Create the same sum function using the lambda
def mysum(arg,*vartuple):
result = arg + sum(vartuple)
return result
l = mysum(1,2,3,4,5,6)
print(l)
mysum = lambda x,y: x+y
l = mysum(5,6)
print(l)
#7. Call the lambda function at the same definition line
(lambda x,y :x+y)(50,60)
#8. Write the difference between the local variable and global variable
'''global : variable is variable defined out of the functions.
local: variable is variable defined in functions.'''