Python String Negative Indexing


Negative Indexing

Use negative indexes to start the slice from the end of the string:

Example

Get the characters from position 5 to position 1, starting the count from the end of the string:

b = "Hello, World!"
print(b[-5:-2])
Try it Yourself »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.