Step-by-step explanation
1) Initialization
data is a tuple with two elements:
data[0] → the list [10, 2]
data[1] → the tuple (3, 4)
2) Function call
result = tuple_sum(data) — inside the function t refers to the same tuple ([10, 2], (3, 4)).
3) Indexing details
t[0][0] → go to first element of t which is [10, 2], then its first element → 10.
t[1][1] → go to second element of t which is (3, 4), then its second element → 4.
4) Addition (digit-by-digit)
10 + 4
units: 0 + 4 = 4
tens: 1 + 0 = 1 → combine → 14
5) Return & print
Function returns 14.
print(result) outputs:
14
Key concept
Accessing nested elements uses multiple indices (t[0][0], t[1][1]).
Tuple immutability is not relevant here because we only read values (not modify). Tuples can hold mutable objects (like lists), but this example only accesses values and sums them.


0 Comments:
Post a Comment