How to Get Last 2 Digits of a Number in Python?
Hi Folks,
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.
Example 1:
main.py
num = 123456 # Get Last 2 Digits from Number lastTwoDigits = num % 100 print(lastTwoDigits)
Output:
56
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
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