-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexamples.py
96 lines (52 loc) · 1.04 KB
/
examples.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
85
86
87
88
89
90
91
92
93
94
95
96
def function_name_using_snake_case(argument1, argument2):
print(argument1, argument2)
return 42
result = function_name_using_snake_case(1, 2)
def function_without_arguments_or_body():
pass
result = function_without_arguments_or_body() # None
a = 1
b = 2
def f(a, b):
print(a, b) # 3, 4
return a + b
result = f(3, 4) # 7
def g():
print(a, b) # 1, 2
return a + b
result = g() # 3
def sum1(xs):
result = 0
for x in xs:
result += x
return result
result = sum1([1, 2, 3])
def sum2(*xs):
result = 0
for x in xs:
result += x
return result
result = sum2(1, 2, 3)
also_result = sum2(*[1, 2, 3])
def keys1(d):
result = []
for key in d:
result.append(key)
return result
# ['a', 'b']
result = keys1(
{
'a': 1,
'b': 2
}
)
def keys2(**d):
result = []
for key in d:
result.append(key)
return result
# ['a', 'b']
result = keys2(a=1, b=2)
d = {'a': 1, 'b': 2}
# ['a', 'b']
also_result = keys2(**d)