Search code snippets, questions, articles... Chrome Extension

Get character from a string using index Python

Strings in python are like arrays and you can get the characters from a try using its index in python.
my_str = "We are here to help"
print(my_str[4]) #prints 'r'
print(my_str[7]) #prints 'h'
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

In the code snippet, there is a variable my_str which contains the characters string. We are getting the characters from the string like we get items from arrays using an index.

If we want to get the 8th character from the given string then we will use the syntax:

Was this helpful?
Join Devsheet Ask a Question