Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q4 of 15
Python - Operators and Expression Evaluation
What will be the output of the following code?
tuple1 = (4, 5, 6)
tuple2 = tuple1
tuple3 = (4, 5, 6)
print(tuple1 is tuple2)
print(tuple1 is tuple3)
AFalse\nTrue
BTrue\nFalse
CTrue\nTrue
DFalse\nFalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand object references

    tuple2 = tuple1 means both variables point to the same object.
  2. Step 2: New tuple object

    tuple3 is a new tuple with the same values but a different object.
  3. Step 3: Evaluate identity

    tuple1 is tuple2 is True, tuple1 is tuple3 is False.
  4. Final Answer:

    True\nFalse -> Option B
  5. Quick Check:

    Same object reference returns True, identical but different objects return False [OK]
Quick Trick: Assignment copies reference; new object with same value is different [OK]
Common Mistakes:
MISTAKES
  • Assuming identical values mean same object
  • Confusing 'is' with '=='
  • Expecting both prints to be True

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes