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
0in the[]to the number that will set the variablecommawith the value,.
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules