Python program to find last 3 digits of a number

In this tutorial, we are going to learn how to find the last 3 digits of a given number in Python.

We can find the 3 digits of a given number by the following Python code:

1.USING MODULO(%) FUNCTION:

num = 23457689
last_three = num % 1000
print(f"The last three digits are: {last_three}")

First, we declare a variable name called num and assign an integer value to it.

In the next step, we declare a variable name called last_three and we do the modulus operation on the given integer number by 1000 it will return the remainder.

The returned remainder is the last 3 digits of a given number.

Output:

The last three digits are: 689

Leave a Reply

Your email address will not be published. Required fields are marked *