-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05.Function.py
82 lines (56 loc) · 1.31 KB
/
05.Function.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
#-*- coding: utf-8 -*-
'''
Functions
See Also: http://docs.python.org/3/tutorial/controlflow.html#defining-functions
http://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions
'''
# Error
#def func():
def func():
pass
def func(num, num1=1, num2=2):
print(num, num1, num2)
func(1, 3, 4) # 1 3 4
func(5) # 5 1 2
# Error
#func()
def func(**args):
for k, v in args.items():
print('key: ' + k, 'value: ' + v)
for k in args.keys():
print('key: ' + k, 'value: ' + args[k])
func(name = "rxb", age = "24")
func(**{"name": "rxb", "age": "24"})
def func(name, age):
print('name: ' + name, 'age: ' + age)
people = {"name": "rxb", "age": "24"}
func(**people) # name: rxb age: 24
def func(num, *args):
print(num)
for a in args:
print(a)
func(1, 2, 3, 4, 5, 6)
def func(num, num1):
print(num, num1)
func(num1 = 2, num = 1) # 1 2
d = {
"num": 3,
"num1": 4
}
func(**d) # 3 4
t = (4, 5)
func(*t) # 4 5
def func():
'''
The documentation of the func
'''
print("func")
print(func.__doc__)
l = lambda num1, num2: num1 + num2
print(l(2, 3)) # 5
def func2(func, num1, num2):
return func(num1, num2)
def func(num1, num2):
return num1 + num2
print(func2(func, 3, 4)) # 7
print(func2(lambda a, b: a - b, 7, 4)) # 3