Home
| Colors: |
February 2026

Get a Substring Slice in Python

You can get part of string in python using the same approach you would use for lists:

input = "alfa bravo charlie"
output = input[:4]
print(output)
Output:
alfa
input = "alfa bravo charlie"
output = input[5:]
print(output)
Output:
bravo charlie
input = "alfa bravo charlie"
output = input[5:10]
print(output)
Output:
bravo

Just another one of the things that makes python super handy for little scripts.

-a

end of line