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 »
print(b[-5:-2])
Related Pages
Python Strings Tutorial String Literals Assigning a String to a Variable Multiline Strings Strings are Arrays Slicing a String String Length Check In String Format String Escape Characters