Arithmetic Operators in Python
Learn about arithmetic operators and their usage in Python.
We'll cover the following...
We'll cover the following...
There are different arithmetic operators that can be applied for mathematical operations: +, -, *, /, %, // and **.
In-place assignment operators offer a good shortcut for arithmetic operations. They include +=, -=, *=, /=, %=, //= and **=.
Operation nuances
On performing floor division a // b, the result is the largest integer which is less than or equal to the quotient. The // operator is called a floor division operator.
In the code above:
- In
-10 // 3, the multiple of 3 that yields -10 is -3.333, whose floor value is-4. - In
10 // -3, the multiple of -3 that yields 10 is -3.333, whose floor value is-4. - In
-10 // -3, the multiple of -3 that yields -10 is 3.333, whose floor value is3.
Note: The
print()function is used for sending output to the screen.
Operation a % b is evaluated as ...