Skip to content
Home » Difference of Two Numbers using abs() Function Python

Difference of Two Numbers using abs() Function Python

Learn about Difference of Two Numbers using abs() Function Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Difference of Two Numbers using abs() Function Python

# Python program to find difference between two numbers

# inputs
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))

# find difference between numbers
diff = abs(num1 - num2)

# print difference value
print('The difference between numbers =', diff)

Output:

Enter first number: 3
Enter second number: 5
The difference between numbers = 2.0

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Python Absolute Difference Between two numbers