Step 1: The list data
data is a list of lists:
So, it has two elements:
-
First element → [1, 2]
-
Second element → [3, 4]
๐ธ Step 2: The for loop
for x, y in data:This line unpacks each inner list into two variables x and y.
-
On first iteration → x = 1, y = 2
-
On second iteration → x = 3, y = 4
๐ธ Step 3: Inside the loop
print(x + y, end=' ')-
First iteration → x + y = 1 + 2 = 3
-
Second iteration → x + y = 3 + 4 = 7
end=' ' keeps the output on the same line.
✅ Final Output:
3 7๐ก Quick Tip:
This is called sequence unpacking — it works when each element in the list (like [1, 2]) contains exactly two items to assign to x and y.


0 Comments:
Post a Comment