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))
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 your answer
Anonymous Quiz
0%
-1
0%
0 0
0%
-4 2
33%
[-4, -1, -6] [2, 5, 3]
22%
[-11] [10]
0%
[10] [-11]
44%
-11 10
0%
10 -11
0%
See solution
What will this code do?
def f(transform, *args):
res = args[0]
for arg in args[1:]:
res = transform(res, arg)
return res
data = [-4, 2, -1, 5, -6, 3]
func = lambda x, n: x * (-1)**n
print(int(f(func, *data)))
Choose your answer
Anonymous Quiz
0%
-720
38%
-4
0%
-1
13%
1
25%
4
13%
[4, -2, 1, -5, 6, -3]
13%
See solution
What will this code do?
def mintwo(*args):
tmp = list(args)
tmp.sort()
return tmp[0], tmp[1]
data = [8, -4, 5, -2, 9, 3, -98]
print(*mintwo(*data))
Choose your answer
Anonymous Quiz
0%
-102
0%
-98
8%
-2
15%
8 -4
69%
-98 -4
0%
9 8
0%
(8, -4)
0%
(9,8)
8%
See solution
What will this code do?
def f(*args):
result = []
for x in args[0]:
if x in result:
continue
for word in args[1:]:
if x not in word:
break
else:
result.append(x)
return ''.join(result)
s1, s2, s3 = "message", "massage", "mask"
print(f(s1, s2, s3))
👍1
Choose your answer
Anonymous Quiz
9%
mesagk
9%
mssa
27%
msa
27%
mesag
9%
message
0%
massage
0%
mask
9%
messagemassagemask
0%
empty line
9%
See solution
👍1
What is the preferred way to check that the variable `a` is associated with None?
Anonymous Quiz
14%
if not a:
7%
if a == None:
57%
if a is None:
14%
if bool(a) == False:
7%
if bool(a) is False:
0%
See solution