A Comprehensive Guide to Slicing in Python

In Python, some objects like strs or lists can sliced. For example, you can get the first element of a list or a string with

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

my_string = "Python"
print(my_string[0]) # P

Python uses square brackets ([ and ]) to access single elements of objects that can be decomposed into parts.

However, there is more to the inside of these square brackets than just accessing individual elements...

Back to Top