Code Explanation:
๐น 1. Creating the Tuple
t = (1, 2, 3)
Here, a tuple named t is created.
It contains three elements: 1, 2, and 3.
Tuples are ordered and immutable (cannot be changed after creation).
๐น 2. Accessing Tuple Elements
Each element in the tuple has an index:
t[0] → 1
t[1] → 2
t[2] → 3
๐น 3. Attempting to Modify the Tuple
t[0] = 10
This line tries to change the first element (1) to 10.
๐น 4. What Actually Happens
Python raises an error:
TypeError: 'tuple' object does not support item assignment
Reason: Tuples are immutable, meaning their values cannot be changed after creation.
Final Output:
Error

0 Comments:
Post a Comment