Question 51
MediumWhat is a shallow copy of a nested list?
- A.
A copy with no elements
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is a shallow copy of a nested list?
A copy with no elements
A reversed copy
A complete independent copy
A new outer list whose elements still refer to the same inner lists
Sign up free to see the answer and a step-by-step explanation.
What does *args collect in a function definition?
Only the first argument
Extra positional arguments, as a tuple
Default values
Keyword arguments, as a dict
Sign up free to see the answer and a step-by-step explanation.
What does the walrus operator := do in Python 3.8+?
Compares two values
Assigns a value inside an expression, as in while (line := f.readline()):
Declares a constant
Swaps two variables
Sign up free to see the answer and a step-by-step explanation.
Which data structure gives O(1) average membership tests in Python?
set
tuple
list
str
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
grid = [[0] * 2] * 2
grid[0][0] = 1
print(grid)
Error
[[1, 0], [1, 0]]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
fs = [lambda: i for i in range(3)]
print(*[f() for f in fs])
0 1 2
2 1 0
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
a = [1, 2]
b = [1, 2]
print(a == b, a is b)
False True
False False
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
a, b, *rest = [1, 2, 3, 4, 5]
print(a, b, rest)
1 2 3
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 deco(f):
def wrapper():
print('start', end=' ')
print(f(), end=' ')
print('end')
return wrapper
@deco
def ten():
return 10
ten()
Error
start end 10
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.append(4)
print(a, b)
[1, 2, 3] [1, 2, 3, 4]
Error
Sign up free to see the answer and a step-by-step explanation.
[[0, 0], [0, 0]]
[[1, 0], [0, 0]]
2 2 2
Error
True True
True False
Error
[1, 2] 3
start 10 end
10
[1, 2, 3] [1, 2, 3]
[1, 2, 3, 4] [1, 2, 3, 4]