Question 61
HardWhat is the output of this program?
def f(a, b=[], *, c=):
b.append(a + c)
b
(f(), f(, c=), f(, []))
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is the output of this program?
def f(a, b=[], *, c=):
b.append(a + c)
b
(f(), f(, c=), f(, []))
[1] [1, 12] [3]
[1] [12] [3]
[1, 12] [1, 12] [3]
[1, 12] [1, 12] [1, 12, 3]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
x = 5
def outer():
x = 10
def inner():
global x
x += 1
return x
return inner(), x
print(outer(), x)
(11, 10) 5
(6, 6) 6
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
funcs = [lambda: i for i in range(3)]
fixed = [lambda i=i: i for i in range(3)]
print([f() for f in funcs], [f() for f in fixed])
[2, 2, 2] [2, 2, 2]
[2, 2, 2] [0, 1, 2]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
a = [[0] * 3] * 3
b = [[0] * 3 for _ in range(3)]
a[0][0] = 1
b[0][0] = 1
print(a[2][0], b[2][0])
0 1
0 0
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
d = {1: "a", True: "b", 1.0: "c"}
print(d, len(d))
{1: 'a'} 1
{True: 'c'} 1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
g = (x * x for x in range(4))
print(sum(g), sum(g), list(map(lambda x: x % 3, range(6))))
30 0 [0, 1, 2, 0, 1, 2]
14 14 [0, 1, 2, 0, 1, 2]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
class A:
def __init__(self): self.v = 1
def __eq__(self, o): return self.v == o.v
print(A() == A(), A() is A(), hash(A) is not None, [1, 2] == [1, 2] and (1, 2) != [1, 2])
True False True True
False False True True
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
s = "Python"
print(s[-1::-2], s[1:5:2], s[10:], s[::-1][:3])
nhy yh None noh
nhy yh noh
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
import copy
a = [1, [2, 3]]
b = copy.copy(a)
c = copy.deepcopy(a)
a[1].append(4)
a[0] = 9
print(b, c)
[1, [2, 3, 4]] [1, [2, 3]]
[1, [2, 3]] [1, [2, 3]]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
def gen():
x = yield 1
print("got", x, end=" ")
yield x * 2
g = gen()
print(next(g), end=" ")
print(g.send(5))
1 got None 10
1 got 5 10
Sign up free to see the answer and a step-by-step explanation.
(11, 11) 5
(6, 10) 6
[0, 1, 2] [2, 2, 2]
[0, 1, 2] [0, 1, 2]
1 0
1 1
{1: 'c'} 1
{1: 'a', True: 'b', 1.0: 'c'} 3
14 0 [0, 1, 2, 0, 1, 2]
14 0 [0, 1, 2, 3, 4, 5]
True True True True
True False True False
yhn yh noh
nhy th noh
[9, [2, 3, 4]] [1, [2, 3]]
[1, [2, 3, 4]] [1, [2, 3, 4]]
1 5 10
got 5 1 10