Skip to content

Operations

  • Lesson
  • 1 min read
  • 3 of 6 in this chapter

Basic Math

We can also do basic math with our variables or with numbers in general, whether integers or floats. Just use + for addition, - for subtraction, * for multiplication, and / for division.

Python
print(5+7)
number1 = 8.5
number2 = 9.3
divided_value = number1/number2
print(divided_value)

OUTPUT

Text
12
0.91397849462

Exponents

To work with exponents, use the ** operator followed by the degree for the number.

Python
Test1 = 5
Test2 = Test1**2
print(Test2)

OUTPUT

Text
25

Modulo Operator

The Modulo Operator can be very useful for certain calculations. It returns the remainder of the division of two numbers.

Python
test1 = 5
test2 = 3
test_r = test1%test2
print(test_r) 

OUTPUT

Text
2

Here, the variable test_r takes the value of the remainder of 5 divided by 3. This is 2, so the output will be 2.