What will this code do?
def f():
def g():
nonlocal x
x = 2
g()
print(x)
f()
👍1
👍1
What will this code do?
def f(name="", value=0):
import sys
func_name = sys._getframe(0).f_code.co_name
func = sys._getframe(1).f_locals[func_name]
setattr(func, name, value)
return sum(func.__dict__.values())
print(f("x", 1), f("y", 2), f())
Choose your answer
Anonymous Quiz
20%
1 1 1
0%
1 2 2
0%
1 2 3
40%
1 3 3
10%
1 2 None
0%
3 3 3
30%
See solution
Choose your answer
Anonymous Quiz
22%
1 2
9%
10 2
30%
10 1 2
4%
None 2
30%
TypeError
4%
See solution
What will this code do?
def f():
x = 1
def g():
x += 1
g()
print(x)
print(f())
Choose your answer
Anonymous Quiz
26%
1
26%
2
11%
None
16%
SyntaxError
21%
UnboundLocalError
0%
See solution
What will this code do?
def func(а, b):
а = 2
b = b[:]
b[0] = 10
a, b = [0], [1]
func(a, b)
print(a, b)
Choose your answer
Anonymous Quiz
0%
[0] [10]
0%
0 10
29%
[0] [1]
6%
0 1
12%
[2] [10]
0%
2 10
18%
[2] [1]
29%
2 [1]
6%
See solution
What will this code do?
def func(а, b):
а[0] = 2
b = b[:]
b[0] = 10
a, b = [0], [1]
func(a, b)
print(a, b)
Choose your answer
Anonymous Quiz
0%
[0] [10]
0%
0 10
27%
[0] [1]
0%
0 1
27%
[2] [10]
7%
2 10
40%
[2] [1]
0%
2 [1]
0%
See solution
What will this code do?
def func(a, b):
a = 2
b[0] = 10
x = 1
y = 1, 2
func(x, y)
print(x, y)
Choose your answer
Anonymous Quiz
7%
1 (1, 2)
7%
2 (1, 2)
20%
1 (10, 2)
13%
2 (10, 2)
0%
1 10
7%
2 10
40%
TypeError
7%
See solution
Which way of passing arguments when calling a function will cause an error?
Anonymous Quiz
9%
f(1, b=2, *(3,), **{"d":4})
45%
f(1, c=3, *(2,), **{"d":4})
9%
f(c=3, b=2, a=1, **{"d":4})
0%
f(*(1, 2), **{"c":3, "d":4})
9%
f(1, *(2, 3), **{"d":4})
9%
f(1, 2, 3, *(4,))
18%
See solution
Which function declaration will not throw an error?
Anonymous Quiz
50%
def f(a, b=1, *c=(2,), **d):pass
13%
def f(a, b, **c, d):pass
38%
def f(a=1, b=2, c):pass
0%
def f(a=1, *b, c):pass
0%
def f(a=1, **b, c):pass
0%
def f(**a, b=1, c):pass
0%
See solution
What will this code do?
def f(s:str = "1") -> int:
return s * 2
print(f(), isinstance(f(), int))