Python Slice Strings


Slicing Strings

You can return a range of characters by using the slice syntax.

Specify the start index and the end index, separated by a colon, to return a part of the string.

Example

Get the characters from position 2 to position 5 (not included):

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


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