Python Basics - Arithmetic Operators

June 29, 2019 | python |

Python has several artithmetic operators: +, -, *, /, %, **, //.

  • + Addition
>>> print(3 + 2)
5
  • - Subtraction
>>> print(3 - 2)
1
  • * Multiplication
>>> print(3 * 2)
6
  • / Division
>>> print(9 / 2)
4.5
  • % Mod (the remainder after dividing)
>>> print(9 % 2)
1
  • ** Exponentiation (note that ^ does not do this operation, as you might have seen in other languages)
>>> print(3 ** 2)
9
  • // Divides and rounds down to the nearest integer
>>> print(9 // 2)
4
Edit this post on GitHub

Leia também