Step-by-step Explanation
1️⃣ lst = [10, 20, 30]
You start with a list of three numbers.
2️⃣ for i in range(len(lst)):
len(lst) = 3, so range(3) generates:
You will loop three times, using each index of the list.
3️⃣ Inside the loop: lst[i] += i
This means:
lst[i] = lst[i] + iNow update values step-by-step:
▶ When i = 0
List becomes:
[10, 20, 30]▶ When i = 1
List becomes:
[10, 21, 30]
▶ When i = 2
List becomes:
[10, 21, 32]Final Output
[10, 21, 32]
Python for GIS & Spatial Intelligence
✅ Summary
This program adds each element’s index to its value.
| Index (i) | Original Value | Added | New Value |
|---|---|---|---|
| 0 | 10 | +0 | 10 |
| 1 | 20 | +1 | 21 |
| 2 | 30 | +2 | 32 |


0 Comments:
Post a Comment