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'
Code faster with devsheet chrome extension and increase productivity as a programmer
search code from your favorite search engine instantly.
Install Now
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
Open Code Manager We are hiring