Google News
logo
Python Program to Get the character at position 1 of a string
In the following example of Python program that demonstrates how to get the character at position 1 of a string :
Program :
# Get the character at position 1 of a string
my_string = "Hello, World!"
print("Original string:", my_string)

char_at_pos_1 = my_string[1]
print("Character at position 1:", char_at_pos_1)
Output :
Original string: Hello, World!
Character at position 1: e
In the above program, we start by assigning the string value `"Hello, World!"` to the variable `my_string`. We then use the `print()` function to print the original value of `my_string`.

Next, we use the square bracket notation to access the character at position 1 of `my_string`. We assign the result of this operation to the variable `char_at_pos_1`.

Finally, we use the `print()` function to print the character at position 1.

As you can see, the character at position 1 of the string is `'e'`.