Skip to main content
RugvAI Labs
Show chat and tutor
Python
Rugv
AI
Labs
Learn
Practice
Reference
Blog
Search...
⌘K
తె
Sign In
RugvAI Labs
All playgrounds →
List Indexing & Slicing
my_list = ["A", "B", "C", "D", "E", "F", "G"]
0
1
2
3
4
5
6
A
B
1
C
2
D
3
E
F
G
-7
-6
-5
-4
-3
-2
-1
my_list
[2]
[1:4]
[:3]
[4:]
[::2]
[-2:]
[::-1]
[1:6:2]
[-3:]
Result
my_list[1:4] =
["B", "C", "D"]
Selects 3 elements. Numbers on badges show selection order.
Syntax:
[start:stop:step]
stop
is exclusive
Negative indices count from the end
[::-1]
reverses the list