If you have any query feel free to chat us!
Happy Coding! Happy Learning!
To find the last digit of an integer in Python, you can use the modulo operator
%
. The modulo operator returns the remainder when the integer is divided by 10, which corresponds to the last digit of the number.Here's how you can find the last digit of an integer in Python:
pythonCopy code
def find_last_digit(number): last_digit = number % 10 return last_digit # Example usage: num = 12345 result = find_last_digit(num) print(f"The last digit of {num} is: {result}")
In this example, the function
find_last_digit()
takes an integernumber
as input and uses the modulo operator%
with the divisor 10 to extract the last digit. The result is then returned as the last_digit variable.For the number 12345, the last digit is 5, and the program will print: “The last digit of 12345 is: 5.”
Comments: 0