Internals & Memory

Preview — 3 of 10 questions

What happens when the following code runs?

javascript
from array import array

arr = array('i', [1, 2, 3])
arr.append(4)
print(arr)
arr.append(2.5)
Aarray('i', [1, 2, 3, 4, 2.5])
Barray('i', [1, 2, 3, 4]), then TypeError: 'float' object cannot be interpreted as an integer
Carray('i', [1, 2, 3, 4]), then 2.5 is silently truncated and appended as 2
Darray('i', [1, 2, 3, 4]), then ValueError: array item exceeds capacity

What is the output of the following code?

javascript
d = {"a": 1, "b": 2, "c": 3}
del d["a"]
d["a"] = 10

print(list(d.keys()))
A['a', 'b', 'c']
B['a', 'c', 'b']
C['b', 'c', 'a']
D['c', 'b', 'a']

What is the output of the following code?

javascript
from collections import Counter

a = Counter(apple=3, banana=2)
b = Counter(apple=1, banana=4)

diff = a - b
a.subtract(b)

print(diff)
print(a)
ACounter({'apple': 2, 'banana': -2}) then Counter({'apple': 2, 'banana': -2})
BCounter({'apple': 2}) then Counter({'apple': 2})
CCounter({'apple': 2}) then TypeError: 'Counter' object has no attribute 'subtract'
DCounter({'apple': 2}) then Counter({'apple': 2, 'banana': -2})

Sign up free to play

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