Get Last 2 Digits of Number in Python Tutorial Example
Hi Dev,
This post will give you an example of getting the last 2 digits of the number in a Python tutorial example. you will learn how to get the last 2 digits of a number in Python. you will learn Python to get the last 2 digits of a number. This post will give you a simple example of getting the last 2 digits of a number in Python. You just need some steps to do how to get the last 2 digits of a number in Python.
In this code, we assign the example number 123456 to the variable num. We then use the modulo operator % to get the remainder of num divided by 100, which is the same as dividing by 10^2 (the number of digits we want to extract). This gives us the last two digits of the number. We store the result in the variable last two digits and print it out.
Example :
main.py
num = 123478
# Get Last 2 Digits from Number
lastTwoDigits = num % 100
print(lastTwoDigits)
Output:
78
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?
- Sort List Descending in Python Tutorial Example