Search code snippets, questions, articles...

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.
Output
r
h

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:

my_str[8]
Was this helpful?
0 Comments