Skip to main content

Arithmetic Operators (+, -, *, /, %)

Arithmetic Operators (+, -, *, /, %) in Python for Programmers

Python supports a wide range of arithmetic operators including the addition (+), subtraction (-), multiplication (*), division (/), and modulo or remainder (%) operators. These operators are used to perform arithmetic operations on numeric values.

These operators can be used in combination with any numeric data type such as integers, floats, and complex numbers.

Examples of Arithmetic Operators in Python

Let's look at some examples of how arithmetic operators are used in Python:

Addition (+)

The addition operator is used to add two or more numeric values together. For example:

x = 5 y = 10 z = x + y print(z)

This code will print the result 15.

Subtraction (-)

The subtraction operator is used to subtract one numeric value from another. For example:

x = 5 y = 10 z = x - y print(z)

This code will print the result -5.

Multiplication (*)

The multiplication operator is used to multiply two or more numeric values together. For example:

x = 5 y = 10 z = x * y print(z)

This code will print the result 50.

Tips for Using Arithmetic Operators in Python

  • Remember that the order of operations matters in Python. Parentheses can be used to enforce a specific order of operations.
  • Be careful when dividing two integers. The result may not be what you expect. To get the expected result, use floats instead of integers.
  • The modulo operator is useful for checking if a number is divisible by another number.