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 Number
lastDigit = 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 Number
lastDigit = num % 10
print(lastDigit)
Output:
8
I hope it can help you...
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?