How to Get Last 2 Digits of a Number in Python?
Today, I would like to show you how to get last 2 digits of a number in python. you will learn python get last 2 digits of number. This article will give you a simple example of get last 2 digits of number python. This post will give you a simple example of how to get last 2 digits of a number in python. you will do the following things for how to get last 2 digits of a number in python.
To get the last 2 digits of a number in Python, you can use the modulo operator %. Here's an example code:
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 lastTwoDigits and print it out.
num = 123456 # Get Last 2 Digits from Number lastTwoDigits = num % 100 print(lastTwoDigits)
I hope it can help you...
We are Recommending you
- Python Get First and Last Digit of a Number Example
- How to Get the Last Digit of a Number in Python?
- How to Get the First Digit of a Number in Python?
- Python Remove All Decimals from Number Example
- Python Convert String to Float with 2 Decimal Places Example
- How to Check If String Contains Word in Python?
- How to Create List of Random Numbers in Python?
- How to Replace Whitespace with Underscore in Python?
- How to Convert HTML to PDF in Python?
- Python String Replace All Numbers Example
- How to Add Element at the End of List in Python?
- How to Find Sum of All Elements in List in Python?
- Python List Remove Element by Value Example
- Python Delete Folder and Files Recursively Example