Get Last 2 Digits of Number in Python Tutorial Example

22-Jun-2023

.

Admin

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

#Python