How to get the first character of a string in Python

To get the first character of a string in Python, you can access the index of that character using the square brackets [] notation.

In Python, all characters in a string are assigned an index number starting from 0 for the first character and incremented by 1 for each subsequent character.

To get the first character, add [0] after the string name as follows:

my_string = "Genius"

print(my_string[0])  # G
print(my_string[1])  # e
print(my_string[2])  # n
print(my_string[3])  # i
print(my_string[4])  # u
print(my_string[5])  # s

You can access any individual character in a string by using its index number. The string index in Python starts from 0.

To get the first character in a string, access the string with [0] notation.

I hope this tutorial helps. Happy coding! 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.