Search
ubuntuversion arithmetic

Arithmetic Operators :

Addition +

Adds values 

Subtraction -

Subtracts second value from first value

Multiplication *

Multiplies values 

Division /

Divides first value by second value

Modulus %

Calculates remainder -> Divides first value by second and returns remainder

Exponent **

Calculates first value to the power of second value

Floor Division //

Divides first value by second value and returns integer value

Example: Addition +

In [12]:
x = 10 

y = 12

print(x + y)
22

Example : Subtraction -

In [13]:
x = 10 

y = 12

print(x - y)
-2

Example : Multiplication *

In [14]:
x = 10 

y = 12

print(x * y)
120

Example : Division /

In [22]:
x = 50

y = 12

print(x / y)
4.166666666666667

Example: Floor Division //

In [23]:
# 50/12= 4.166666666666667  50//12= 4   -> // removes the digits after the decimal point

x = 50

y = 12

print(x // y)
4

Example : Modulus %

In [24]:
# 50 = 4*12 + 2 (remainder)

x = 50  

y = 12

# Prints remainder
print(x % y)
2

Example : Exponent **

In [26]:
# 2 to the power of 3

x = 2

y = 3

print(x ** y)
8