Collections Basics — Series 2

Preview — 3 of 10 questions

What is the output of the following code?

javascript
print(all([]))
print(any([]))
print(all([1, 2, 3]))
print(any([0, 0, 3]))
print(all([1, 0, 3]))
AFalse, True, True, True, False — all([]) is False since an empty iterable can't satisfy "all" conditions.
BTrue, False, True, False, True
CTrue, False, True, True, False
DTrue, True, True, True, True

What is the output of the following code?

javascript
a = [1, 2]
b = [1, 2]
a.append([3, 4])
b.extend([3, 4])
print(a)
print(b)
A[1, 2, [3, 4]], then [1, 2, 3, 4]
B[1, 2, 3, 4], then [1, 2, [3, 4]]
C[1, 2, 3, 4], then [1, 2, 3, 4]
DTypeError: append() takes exactly one argument (2 given)

What is the output of the following code?

javascript
nums = [1, 2, 2, 3, 2, 4]
print(nums.count(2))
print(nums.count(5))
A2, 0
B3, ValueError
C2, ValueError
D3, 0

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.