Arithmetic Operators: Exercises


2. Subtraction Operator. In Python, scalar subtraction can be performed with the operator -.

In the exercise below, start by defining two variables, a=7 and b=8.

Next, subtract a from b, and assign the difference to a third variable, c.

Finally, use the print() function to print c to the console.


# Define a and b. a = ___ ___ = ___ # Subtract a from b. c = ___ # Print c. print(___) # Define a and b. a = 7 b = 8 # Subtract a from b. c = b - a # Print c. print(c) test_object("a") test_object("b") test_object("c") success_msg("Correct! Notice that - can also be used to perform elementwise subtract between numpy arrays.")
You can use the - operator to subtract one number from another.

Previous Exercise Next Exercise