Collections Basics — Series 3

Preview — 3 of 10 questions

What is the output of the following code?

javascript
a = [1, 2, 3]
b = a
c = a.copy()
d = a[:]
b.append(4)
c.append(5)
d.append(6)
print(a)
print(b is a)
print(c is a)
print(d is a)
A[1, 2, 3, 4], True, False, False
B[1, 2, 3], False, False, False
C[1, 2, 3, 4, 5, 6], True, False, False
D[1, 2, 3, 4], True, True, True

What is the output of the following code?

javascript
print(tuple([1, 2, 3]))
print(tuple("abc"))
print(tuple({"x": 1, "y": 2}))
A(1, 2, 3), ('a', 'b', 'c'), (('x', 1), ('y', 2))
B(1, 2, 3), ('a', 'b', 'c'), ('x', 'y')
C[1, 2, 3], ('abc',), ('x', 'y')
D(1, 2, 3), ('abc',), (('x', 1), ('y', 2))

What is the output of the following code?

javascript
d = {"a": 1, "b": 2, "c": 3}
print(list(d.keys()))
print(list(d.values()))
print(list(d.items()))
print(type(d.keys()))
A[1, 2, 3], ['a', 'b', 'c'], [('a', 1), ('b', 2), ('c', 3)], <class 'dict_keys'>
B['a', 'b', 'c'], [1, 2, 3], {'a': 1, 'b': 2, 'c': 3}, <class 'dict_keys'>
C['a', 'b', 'c'], [1, 2, 3], [('a', 1), ('b', 2), ('c', 3)], <class 'dict_keys'>
D['a', 'b', 'c'], [1, 2, 3], [('a', 1), ('b', 2), ('c', 3)], <class 'list'>

Sign up free to play

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