Skip to content
Home » Subtract Two Numbers in Python using Numpy

Subtract Two Numbers in Python using Numpy

Learn about Subtract Two Numbers in Python using Numpy in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Subtract Two Numbers in Python using Numpy

# Python program to subtract two numbers

import numpy

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

# subtraction
sub = numpy.subtract(num1, num2)

# print result
print('The subtraction of numbers = %0.1f' %sub)

Output:

Enter first number: 8
Enter second number: 6
The subtraction of 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 Program to Subtract Two Numbers using Function