Which way to pass arguments when calling a function will cause an error?
Anonymous Quiz
6%
f(1, b=2, *(3,), **{"d": 4})
56%
f(1, c=3, *(2,), **{"d": 4})
0%
f(c=3, b=2, a=1, **{"d": 4})
6%
f(*(1, 2), **{"c": 3, "d": 4})
6%
f(1, *(2, 3), **{"d": 4})
13%
f(1, 2, 3, *(4,))
13%
See solution
Which function declaration will not cause an error during function creation?
Anonymous Quiz
8%
def f(a, b=1, *c=(2,), **d): pass
23%
def f(a, b, **c, d): pass
54%
def f(a=1, b=2, c): pass
8%
def f(a=1, *b, c): pass
8%
def f(a=1, **b, c): pass
0%
def f(**a, b=1, c): pass
What will this code do?
x = 1
def f():
def g():
nonlocal x
print(x)
x += 1
return g
Choose the correct answer
Anonymous Quiz
20%
1
7%
2
7%
None
7%
SyntaxError
47%
UnboundLocalError
13%
NameError
0%
See solution
Given code:
def f(a, b, c, d, e):
print(a, b, c, d, e)
f(1, *(3,), c=10, **{"d": 5, "e": 100})
What will this code output?
Anonymous Quiz
7%
1 10 3 5 100
64%
1 3 10 5 100
0%
1 3 None 10 5 100
14%
SyntaxError
7%
TypeError
7%
NameError
0%
See solution
What will this code do?
def f(s:str = "1") -> int:
return s * 2
print(f(), isinstance(f(), int))
Choose the correct answer
Anonymous Quiz
13%
2 True
0%
2 False
20%
11 True
60%
11 False
7%
See solution
What will this code do?
def maker(f, args, kwargs):
return 1 + f(*args, **kwargs)
m1 = maker(lambda a, b: a + b, (5, ), {"b": 2})
m2 = maker(lambda a, b: a * b, [4, 5], {})
print(m1 + m2)
What will this code do?
def f(test, *args):
res = []
for arg in args:
if test(arg):
res.append(arg)
return sum(res)
data = [-4, 2, -1, 5, -6, 3]
negative = lambda x: x < 0
neg = f(negative, *data)
positive = lambda x: x > 0
pos = f(positive, *data)
print(neg, pos)
Choose the correct answer
Anonymous Quiz
0%
-1
0%
0 0
0%
-4 2
9%
[-4, -1, -6] [2, 5, 3]
27%
[-11] [10]
0%
[10] [-11]
64%
-11 10
0%
-10 11
0%
See solution
What will this code do?
x = 1
def f():
def g():
nonlocal x
print(x)
x += 1
return g
Choose your answer
Anonymous Quiz
16%
1
26%
2
0%
None
21%
SyntaxError
32%
UnboundLocalError
5%
NameError
0%
See solution
What will this code do?
def f(a, b, c, d, e):
print(a, b, c, d, e)
f(1, *(3,), c=10, **{"d": 5, "e": 100})
Choose your answer
Anonymous Quiz
7%
1 10 3 5 100
71%
1 3 10 5 100
7%
1 3 None 10 5 100
7%
SyntaxError
7%
TypeError
0%
NameError
What will this code do?
def f(s:str = "1") -> int:
return s * 2
print(f(), isinstance(f(), int))
Choose the correct answer
Anonymous Quiz
17%
2 True
0%
2 False
8%
11 True
75%
11 False
0%
See solution
What will this code do?
def maker(f, args, kwargs):
return 1 + f(*args, **kwargs)
m1 = maker(lambda a, b: a + b, (5, ), {"b": 2})
m2 = maker(lambda a, b: a * b, [4, 5], {})
print(m1 + m2)