find the first character in a string in python

To find the first character in a string in Python, you can simply use square brackets with the index of 0 to access the first character of a string. Here's an example:

main.py
my_string = "hello world"
first_char = my_string[0]
print(first_char)  # Output: 'h'
85 chars
4 lines

In this example, we first create a string variable my_string which contains the value "hello world". We then use square brackets with the index of 0 to access the first character of the string and store it in the variable first_char. Finally, we print the value of the first_char variable, which should output 'h'.

related categories

gistlibby LogSnag