Languages
[Edit]
EN

Python - get last character of string

0 points
Created by:
Hiba-Tate
548

In this article, we would like to show you how to get the last character of a string in Python.

Quick solution:

last_character = string[-1]

 

Practical example

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:

string = "dirask"
last_character = string[-1]
print("The last character is:", last_character)

 Output:

The last character is: k

See also

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - get last character of string

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join