What is the output of print([1, 2] == [1, 2]) in Python?
Correct answer
D. True
7 views
D. True
7 views
The == operator compares the values inside two objects, and both lists hold the same items in the same order, so the result is True. A useful fact to remember is that == checks equality of values, while the "is" operator checks whether two names point to the very same object, so [1, 2] is [1, 2] would give False. Option A (False) is wrong because the contents and order of both lists match exactly. Option B (Error) is wrong because comparing two lists with == is perfectly valid Python. Option C (None) is wrong because a comparison always returns a Boolean value, either True or False, and never None.
Asked in: Python Interview Data Types
https://docs.python.org/3/library/stdtypes.htmlNot sure why the answer is D? Ask here and get an explanation.