Question 31
MediumWhat is the output of this program?
a = [1, 2, 3, 4]
(a[:])
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?
a = [1, 2, 3, 4]
(a[:])
[2, 3, 4]
[1, 2, 3]
[1, 2]
[3, 4]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
for i, ch in enumerate('ab'):
print(i, ch, end=' ')
0 1 a b
0 a 1 b
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
print(list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4])))
[True, False]
[1, 2, 3, 4]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
def gen(n):
for i in range(n):
yield i
print(*gen(3))
0 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?
a = [1, 2, 3]
b = a
b += [4]
c = a[:]
c.append(5)
print(a, len(c))
[1, 2, 3] 5
[1, 2, 3, 4] 5
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
def f(x, items=None):
if items is None:
items = []
items.append(x)
return items
print(f(1), f(2))
[1, 2] [1, 2]
[1] [1, 2]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
print([x * y for x in range(1, 4) for y in range(x, 4)])
[1, 2, 3, 4, 6, 9]
[1, 4, 9]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
d = {"a": 1, "b": 2}
d2 = {**d, "b": 3, "c": 4}
print(d2, len(d))
{'a': 1, 'b': 2, 'c': 4} 2
{'a': 1, 'b': 3, 'c': 4} 2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
s = "Placement2026"
print(s[::-1][:4], s[-4:], s[1:9:3])
6202 2026 lct
2026 6202 len
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
x = 10
def outer():
x = 20
def inner():
nonlocal x
x += 5
return x
return inner() + x
print(outer(), x)
50 25
50 10
Sign up free to see the answer and a step-by-step explanation.
Error
a 0 b 1
[1, 3]
[2, 4]
0 1 2
Error
[1, 2, 3, 4] 4
[1, 2, 3, 4, 5] 5
[1] [2]
[2] [2]
[1, 2, 3]
[1, 2, 3, 2, 4, 6, 3, 6, 9]
{'a': 1, 'b': 3, 'c': 4} 3
{'b': 3, 'c': 4} 2
6202 2026 len
6202 2026 Pcm
45 10
35 10