English

What will be the output of the following code? tuple1 = (1, 2, 3) tuple2 = tuple1 tuple1 += (4,) print(tuple1 == tuple2) - Computer Science (Python)

Advertisements
Advertisements

Question

What will be the output of the following code? 

tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)

Options

  • True

  • False

  • tuple1

  • Error

MCQ

Solution

False

Explanation:

  1. Initially, both tuple1 and tuple2 are (1, 2, 3).

  2. Tuples are immutable, so when we do tuple1 += (4,), it creates a new tuple (1, 2, 3, 4) and assigns it to tuple1.

  3. Now, tuple1 is (1, 2, 3, 4), but tuple2 is still (1, 2, 3).

  4. Comparison:

    • (1, 2, 3, 4) is not equal to (1, 2, 3).
    • So, the result will be False.
shaalaa.com
  Is there an error in this question or solution?
2024-2025 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×