find the last character in a string in python

You can find the last character of a string in Python using negative indexing. Here's an example code snippet:

main.py
my_string = "Hello, World!"
last_char = my_string[-1]
print(last_char)
71 chars
4 lines

In the above code, my_string[-1] returns the last character of the string "Hello, World!", which is "!". Negative indexing allows you to access elements from the end of the string, with -1 being the index for the last character.

related categories

gistlibby LogSnag