Step-by-step explanation:
-
Dictionary d → {1:10, 2:20, 3:30}
-
Keys → 1, 2, 3
-
Values → 10, 20, 30
-
-
.items()
-
Returns key-value pairs as tuples:
(1, 10), (2, 20), (3, 30)
-
-
Loop:
-
First iteration → k=1, v=10 → print(1+10) → 11
-
Second iteration → k=2, v=20 → print(2+20) → 22
-
Third iteration → k=3, v=30 → print(3+30) → 33
-
-
end=' '
-
Keeps output on one line separated by spaces.
-
✅ Output:
11 22 33
Concept Used:
Looping through a dictionary using .items() gives both key and value, allowing arithmetic or logic to be performed on them together.


0 Comments:
Post a Comment