Language: EN

python-operadores-aritmeticos

Arithmetic Operators in Python

Arithmetic operators allow us to perform mathematical operations on numbers.

List of arithmetic operators

Sum (+)

The addition operator (+) is used to add two numbers. It can also be used to concatenate strings and lists in Python.

a = 5
b = 3
result = a + b  # result is 8

Subtraction (-)

The subtraction operator (-) is used to subtract one number from another.

a = 10
b = 7
result = a - b  # result is 3

Multiplication (*)

The multiplication operator (*) is used to multiply two numbers.

a = 5
b = 4
result = a * b  # result is 20

Division (/)

The division operator (/) is used to divide one number by another. In Python 3, division always returns a floating-point number (float).

a = 10
b = 2
result = a / b  # result is 5.0

Integer Division (//)

The integer division operator (//) is used to divide one number by another and return the integer quotient, discarding any decimal part.

a = 10
b = 3
result = a // b  # result is 3

Modulo (%)

The modulo operator (%) is used to get the remainder of a division between two numbers.

a = 10
b = 3
result = a % b  # result is 1

Power (**)

The power operator (**) is used to raise a number to a power.

a = 2
b = 3
result = a ** b  # result is 8