Get Character at Specific Index from String

To get character at specific index from a string in Python, keep the opening and closing square brackets after the string variable and mention the index inside the brackets, as shown in the following.

</>
Copy
myString[index]

Example

In the following program, we take a string in name variable, and access the characters at index 0 and 3 using square brackets notation.

main.py

</>
Copy
name = 'apple'

index = 0
ch = name[index]
print(f'name[{index}] : {ch}')

index = 3
ch = name[index]
print(f'name[{index}] : {ch}')

Output

name[0] : a
name[3] : l

Conclusion

In this Python Tutorial, we learned how to get character at specific index from a string in Python using square brackets notation.