How to Get the Last Digit of a Number in Python?
This detailed guide will cover python get last digit of a number. In this article, we will implement a how to get last digit of a number in python. This example will help you program to find last digit of a number python. It's a simple example of last digit of a number in python. Let's see below example find last digit of a number in python.
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.
number1 = 43567 # Get Last Digit from Number lastDigit = str(number1)[-1] lastDigit = int(lastDigit) print(lastDigit)
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.
number = 9658 # Get last Digit from Number lastDigit = num % 10 print(lastDigit)
I hope it can help you...
We are Recommending you
- Python Remove All Decimals from Number Example
- Python Convert String to Float with 2 Decimal Places Example
- How to Sort List Descending in Python?
- How to Create an Alphabet List in Python?
- Python Search String in File and Print Line Example
- How to Check If Element is Present in List Python?
- How to Modify JSON File in Python?
- How to Check If a List is Empty or Not in Python?
- Python String Convert to Lowercase Example
- How to Get Min Value from Python List?
- How to Remove null Values from the List in Python?
- How to Remove Last Element from List in Python?
- Python Post Request with Json File Example
- Python Copy File From one Directory to Another Example