Step 1: Understand slicing
The syntax is:
list[start : stop : step]-
start → index to begin from (inclusive).
-
stop → index to stop before (exclusive).
-
step → how many steps to jump each time.
Step 2: Apply to this code
-
lst = [10, 20, 30, 40, 50]
(indexes → 0:10, 1:20, 2:30, 3:40, 4:50) lst[1:4:2] means:
-
Start from index 1 → 20
-
Go up to index 4 (but don’t include it)
-
Step by 2
-
Step 3: Pick the elements
-
Index 1 → 20
-
Index 3 → 40
๐ So result = [20, 40]
✅ Final Output:
[20, 40]


0 Comments:
Post a Comment