Question discussion

What is the output of the following Python code?a = [1, 2] b = a c = [1, 2] print(a is b, a is c, a == c)

2515Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Python code?

a = [1, 2]
b = a
c = [1, 2]
print(a is b, a is c, a == c)
  • ATrue False True
  • BTrue True True
  • CFalse False True
  • DTrue False False
Correct answer: A

Explanation

b refers to the same list object as a, so a is b is True; c is a different object with equal contents, so a is c is False but a == c is True.

Discussion 0

Nobody has replied yet. Start the discussion!