Practice With Arithmetic Operators

Practice these programming examples to internalize these concepts.

3. Addition and Subtraction

In Python, addition and subtraction operators perform just as they do in mathematics. In fact, you can use the Python programming language as a calculator.

Let's look at some examples, starting with integers:

print(1 + 5)



Instead of passing integers directly into the print statement, we can initialize variables to stand for integer values:

a = 88
b = 103
print(a + b)



Because integers can be both positive and negative numbers (and 0 too), we can add a negative number with a positive number:

c= -36
d = 25
print(c + d)



Addition will behave similarly with floats:

e = 5.5
f = 2.5
print(e + f)



Because we added two floats together, Python returned a float value with a decimal place.

The syntax for subtraction is the same as for addition, except you'll change your operator from the plus sign (+) to the minus sign (-):

g = 75.67
h = 32
print(g - h)



Here, we subtracted an integer from a float. Python will return a float if at least one of the numbers involved in an equation is a float.