Python Subtraction – Arithmetic Operator
Python Subtraction Operator takes two operands, first one on left and second one on right, and returns difference of the the second operand from the first operand.
The symbol used for Python Subtraction operator is
Following is the syntax of Python Subtraction Arithmetic Operator with two operands.
result = operand_1 - operand_2
operand_2 are numbers and the result is the difference of
Example 1: Subtraction of Numbers
In this example, we shall take two integers, subtract them, and print the result.
a = 20 b = 12 result = a - b print(result)
Chaining of Subtraction Operator
You can subtract more than one number from a number in a single statement. This is because, Subtraction Operator supports chaining.
a = 63 b = 12 c = 5 d = 10 result = a - b - c - d print(result)
Example 2: Subtraction of Floating Point Numbers
Float is one of the numeric datatypes. You can compute the difference of floating point numbers using Python Subtraction operator.
a = 12.5 b = 10.2 result = a - b print(result)
Example 3: Subtraction of Complex Numbers
You can find the subtraction of complex numbers using
-. In the following example program, we shall take two complex numbers and find their difference.
a = 1 + 8j b = 3 + 5j result = a - b print(result)
In this tutorial of Python Examples, we learned what Python Subtraction Arithmetic Operator is, how to use it to find the difference of two or more numbers.