# How To Get Last Digit Of A Number In Python

May 9, 2023 | Category : Other

Hi Dev,Hey,
Now, let's see a tutorial of python get last digit of a number. we will help you to give an example of how to get last digit of a number in python. Here you will learn program to find last digit of a number python. This article will give you a simple example of last digit of a number in python. So, let us dive into the details.

There are several ways to get the last digit of a number in Python. I will give you two simple examples to get the last digit from a number. You can see both examples one by one.

Example 1:

main.py

`number1 = 43567  # Get Last Digit from NumberlastDigit = str(number1)[-1]lastDigit = int(lastDigit)    print(lastDigit)`

Output:

`7`

Example 2:

You can get the last digit of a number in Python using the modulus operator (%). Here's an example code:

In this example, the modulus operator % returns the remainder of the division of num by 10, which is the last digit of num.

main.py

`number = 9658  # Get last Digit from NumberlastDigit = num % 10print(lastDigit)`

Output:

`8`