Chapter 1.8 - Operators

Chapter 1.8 Operators

For more complex mathematical operations, common mathematical operators are available.


Operators
operator      operation      example      code     
+ addition 3+2 a = 3+2
- subtraction 3-2 b = 3-2
* multiplication 3*2 c=3*2
/ division 10/2 d=10/2
// floor division e=10//3
** power 23 f=2**3
% modulus g=8%3

Try to check the results of the code in two lines, first calculating the result of the operation and then print the result like the following code.

a = 3 + 2
print(a)

“Floor division” will always round the answer down to the nearest integer. For example, 11//2 will be 5, not 5.5, and 99//100 will equal 0.


The official style guide for Python says that there should be a space before and after each operator