Explanation:
1. Creating a Tuple
t = (1,2,3)
Here, a tuple named t is created.
The tuple contains three elements: 1, 2, and 3.
Tuples are written using parentheses ( ).
Important property: Tuples are immutable, meaning their values cannot be changed after creation.
Result:
t → (1, 2, 3)
t[0] = 5
t[0] refers to the first element of the tuple.
Python uses indexing starting from 0:
t[0] → 1
t[1] → 2
t[2] → 3
This line tries to change the first element from 1 to 5.
However, tuples do not allow modification because they are immutable.
Result:
Python raises an error.
Error message:
TypeError: 'tuple' object does not support item assignment
3. Printing the Tuple
print(t)
This line is supposed to print the tuple t.
But because the previous line produced an error, the program stops execution.
Therefore, print(t) will not run.
✅ Final Conclusion
Tuples are immutable in Python.
You cannot change elements of a tuple after it is created.
The program will stop with a TypeError before printing anything
Final Output:
Error

0 Comments:
Post a Comment