What is the output of the following Python code snippet?
a = 256; b = 256
x = [1]; y = [1]
print(a is b, x is y)
x = [1]; y = [1]
print(a is b, x is y)
Correct answer
A. True False
A. True False
Small integers are cached by CPython so a is b is True, but two separately built lists are different objects.
Asked in: Python Interview Data Types
https://docs.python.org/3/library/stdtypes.htmlNot sure why the answer is A? Ask here and get an explanation.