EN
Python - get last character of string
0 points
In this article, we would like to show you how to get the last character of a string in Python.
Quick solution:
xxxxxxxxxx
1
last_character = string[-1]
In this example, we get the last character of the "dirask"
string by index.
Note:
In Python each character in a string has an index number associated with it. We can use the index to access any character.
Code:
xxxxxxxxxx
1
string = "dirask"
2
last_character = string[-1]
3
print("The last character is:", last_character)
Output:
xxxxxxxxxx
1
The last character is: k