Get First Character from String

To get the first character from a string in Python, access the character from string using square brackets and pass the index 0.

The following expression returns the first character from the string myString.

myString[0]

Example

In the following program, we take a string in name variable, and get the first character using square brackets notation and 0 index.

main.py

name = 'banana'

firstChar = name[0]
print(f'First Character : {firstChar}')
Try Online

Output

First Character : b
ADVERTISEMENT

Conclusion

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