- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path014_functions.py
More file actions
Latest commit
50 lines (31 loc) · 813 Bytes
/
Copy path014_functions.py
File metadata and controls
50 lines (31 loc) · 813 Bytes
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
# functions!
defget_sum(a, b):
returna+b
print(get_sum(1, 2))
# if you dont know how many values you're gonna get
# just use *args
# remember to put it last
# ex: get_sum(a, b, *args)
defget_sum_2(*args):
sum=0
forarginargs:
sum+=arg
returnsum
print(get_sum_2(1, 2, 3, 4, 5))
# get both values
defnext_2(nums):
returnnum+1, num+2
ret_1, ret_2=next_2(5)
print(ret_1, ret_2)
# create a function that returns a function
defmult_by(num):
returnlambdax: x*num
print(" 3 * 5 =", (mult_by(3)(5)))
# pass a function to a function
defmult_list(list, func):
forxinlist:
print(func(x))
mult_by_4=mult_by(4)
mult_list(list(range(0, 5)), mult_by_4)
# you can create a list of function
power_list= [lambdax: x**2, lambdax: x**3]