Step-by-step explanation:
-
arr = [5, 10, 15]
→ A list (array) with three elements. -
range(0, len(arr), 2)
→ This generates a sequence of numbers starting from 0 up to len(arr)-1 (which is 2),
→ but it skips every 2nd number.
So the output of range(0, len(arr), 2) is:
๐ [0, 2] -
Loop runs like this:
-
When i = 0 → arr[i] = arr[0] = 5
-
When i = 2 → arr[i] = arr[2] = 15
-
-
print(arr[i], end=' ')
→ Prints the selected elements on the same line (because of end=' ').
✅ Output:
5 15
๐ The code prints elements at even indices (0 and 2) from the list.


0 Comments:
Post a Comment