Arithmetic Python Operators

by Josh on 01/01/2024

Arithmetic operators in Python are used to perform mathematical operations such as addition, subtraction, multiplication, division, and more. Here are some common arithmetic operators and examples of how to use them:

  • Addition (+): Adds two numbers.
    result = 10 + 5  # result is 15
  • Subtraction (-): Subtracts the second number from the first.
    result = 10 - 5  # result is 5
  • Multiplication (*): Multiplies two numbers.
    result = 10 * 5  # result is 50
  • Division (/): Divides the first number by the second.
    result = 10 / 5  # result is 2.0
  • Floor Division (//): Divides the first number by the second and returns the largest integer less than or equal to the result.
    result = 10 // 3  # result is 3
  • Modulus (%): Returns the remainder of the division of the first number by the second.
    result = 10 % 3  # result is 1
  • Exponentiation (**): Raises the first number to the power of the second.
    result = 2 ** 3  # result is 8