forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_args.py
More file actions
44 lines (33 loc) · 697 Bytes
/
function_args.py
File metadata and controls
44 lines (33 loc) · 697 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
def sum(x, y):
return x+y
# def total(a, b, c, d):
# return sum(sum(a,b), sum(c,d))
#
# assert total(1,1,1,1) == 4
# assert total(1,2,3,4) == 10
assert sum(1, 1) == 2
assert sum(1, 3) == 4
def sum2y(x, y):
return x+y*2
assert sum2y(1, 1) == 3
assert sum2y(1, 3) == 7
def va(a, b=2, *c, d, **e):
assert a == 1
assert b == 22
assert c == (3, 4)
assert d == 1337
assert e['f'] == 42
va(1, 22, 3, 4, d=1337, f=42)
def va2(*args, **kwargs):
assert args == (5, 4)
assert len(kwargs) == 0
va2(5, 4)
x = (5, 4)
va2(*x)
va2(5, *x[1:])
# def va3(x, *, b=2):
# pass
# va3(1, 2, 3, b=10)
x = {'f': 42, 'e': 1337}
y = {'d': 1337}
va(1, 22, 3, 4, **x, **y)