Arithmetic operators

In Python there are the usual arithmetic operators, as in most other programming languages, namely addition, subtraction, multiplication, division and the remainder operator (modulo). In addition, there are the one-digit operators for positive and negative sign as well as operators for exponential (power) calculation and floor division. The arithmetic operators expect numeric operands and return a numeric return value.

OperatorDescription
+Addition / sign
Subtraction / sign
*Multiplication
/Division (float)
//Division (floor)
%Rest (modulo)
**Exponent (power)

Example

Code Explanation

LineDescription
1Initializes the variables
a with value 6,
b with value 4,
c with value 8 and
z with value 0
3 – 4Output starting values
7 – 8Outputs the division of the variables a and b
10 – 11Outputs the division (floor) of the variables a and b
13 – 14Outputs the power of the variables a and b.
16 – 17Multiplication of the variables a and b followed by subtraction of the variable z
a, b, c, z = 6, 4, 8, 0

print("Starting values")
print("a = " + str(a) + "\nb = " + str(b) + "\nc = " + str(c) + "\nz = " + str(z))

print("Calculations")
z = a / b
print("z = " + str(a) + " / " + str(b) + " = " + str(z))

z = a // b
print("z = " + str(a) + " // " + str(b) + " = " + str(z))

z = a ** b
print("z = " + str(a) + " ** " + str(b) + " = " + str(z))

a = z - a * b
print("a = " + str(a))
Output
Starting values
a = 6
b = 4
c = 8
z = 0
Calculations
z = 6 / 4 = 1.5
z = 6 // 4 = 1
z = 6 ** 4 = 1296
a = 1272