Editor settings

General settings

Save settings

Learn to program with Python

Access a letter in a string #

Once you have a string, you can access individual characters in the string using the characters [] and an index. An index is a numeric value that represents the position of an element within a sequence, such as a string or a list. The first element in a sequence has an index of 0, the second has an index of 1, and so on.

Here's an example on how to get the first letter of a string:

my_string = "Hello, World!"
first_character = my_string[0]
print(first_character) # Output: H

Exercise #

  • Change the number 0 in the [] to the number that will set the variable comma with the value ,.
Output will be displayed here