ProgrammingHardProduct Company SDE · Python internals
What does the following Python 3 code print? print([] == False, [] is False)
- A. False True
- B. False False
- C. True True
- D. True False
Correct answer: B. False False
[] is falsy in a boolean context but it is never equal to the bool False, and 'is' checks identity, which also fails here.
More Python Programming questions
- What does the following Python 3 code print? x = [1, 2, 3] y = [1, 2, 3] print(x == y, x is y)
- What does the following Python 3 code print? print(2 10, 2 0.5, 10 // 3, -10 // 3, 10 % 3, -10 % 3)
- What does the following Python 3 code print? print(id([1, 2]) == id([1, 2]))
- What does the following Python 3 code print? try: a = (1, 2, 3) a[0] = 9 except TypeError: print("TypeError")
- What does the following Python 3 code print? try: d = {} print(d["missing"]) except KeyError: print("KeyError")
- What does the following Python 3 code print? try: s = "abc" print(s[10]) except IndexError: print("IndexError")