Lesson 22 of 55
8 mins readPython Array Slices & Range Operators
In Plain English
Array slicing extracts a subset of elements into a new list. Because multiple elements are returned, slices use the `@` sigil (e.g. `@items[0, 2, 4]`).
Deep Dive: How It Works
Slice Sigil (@): Extracting multiple elements produces a list, so use `@arr[...]`.
Range Slicing: `@arr[1..3]` extracts items from index 1 through 3.
Slice Assignment: `@arr[0, 1] = ("new1", "new2")` updates multiple positions at once.
Core Rules to Remember

Array Slice Sigil: `@array[1, 3]` uses `@` because the result is a list.

Range Operator (..): `(1..10)` generates sequential integers or letters (`"a".."z"`).
Live Interactive Example
Hit Run Code to see it liveExtracting Array Slices
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output Console
Click "Run Code" to view the rendered output.
How it works: Array slices cleanly pulled out the selected index ranges.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Extract Weekend Days
Declare `my @days = qw(Mon Tue Wed Thu Fri Sat Sun);`
Extract weekend days using slice `@days[5, 6]` into `my @weekend`.
Print `"Weekend: " . join(" & ", @weekend) . "\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.