Slicing Lists and Strings in Python


Use slicing to access parts of lists or strings.

Source Code

my_list = [0, 1, 2, 3, 4]
print(my_list[1:3])  # [1, 2]

my_string = "Hello"
print(my_string[:2])  # "He"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments