Code Explanation:
๐น 1. Creating a Tuple
t = (1, 2, 3, 4)
A tuple named t is created.
It contains 4 elements: 1, 2, 3, 4.
Tuples are immutable → you cannot change their values directly.
๐น 2. Starting a Loop
for i in t:
This is a for loop that iterates over each element of the tuple.
On each iteration, i takes one value from t.
Iteration steps:
1st → i = 1
2nd → i = 2
3rd → i = 3
4th → i = 4
๐น 3. Modifying the Loop Variable
i += 10
This adds 10 to the current value of i.
But important point:
It does NOT change the tuple
It only changes the temporary variable i
So values become:
1 → 11
2 → 12
3 → 13
4 → 14
But these values are not stored anywhere.
๐น 4. Printing the Tuple
print(t)
This prints the original tuple.
Since tuples are immutable and unchanged, output remains the same.
✅ Final Output
(1, 2, 3, 4)

0 Comments:
Post a Comment