Python: Arithmetic Operator

Python: Arithmetic Operator

  • +, addition
  • -, subtraction
  • *, multiplication
  • /, division
  • **, exponentiation
  • %, modulo (return the remainder)
  • //, integer division (it rounds down the answer down to an interger)
  • ^, bitwise XOR
print(3**2) # output: 9
print(7%3) # output: 1
print(-9//2) # output: -5

Mathematical order of operations:
1. exponents and roots
2. multiplication and division
3. addition and subtraction
—— [ wikipedia ]

猜你喜欢

转载自blog.csdn.net/guo_ya_nan/article/details/80257457