Skip to content
Justice Tech School

String Slicing and Indexing

Index from 0 or from the end with negatives. s[a:b:step] slices. Strings are immutable.

Example
s = "Python"
print(s[0], s[-1], s[1:4], s[::-1], s[::2])

Result

P n yth nohtyP Pto

Exercise

Reverse a string.

s[]

Quiz Test

What is s[-1]?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.