Explanation:
๐น Line 1: Tuple Creation
x = (1, 2, 3)
A tuple named x is created.
It contains three elements: 1, 2, and 3.
Important: Tuples in Python are immutable, meaning their values cannot be changed after creation.
๐น Line 2: Attempt to Modify Tuple
x[0] = 10
This line tries to change the first element (index 0) of the tuple to 10.
However, since tuples are immutable, Python does not allow item assignment.
๐น What Happens Internally
Python detects that you're trying to modify a tuple.
It raises an error:
TypeError: 'tuple' object does not support item assignment
๐น Final Result
The code does not execute successfully.
❌ It results in an Error.

0 Comments:
Post a Comment