python-operadores-aritmeticos

Arithmetic Operators in Python

  • 2 min

Arithmetic operators allow us to perform mathematical operations on numbers. The basic arithmetic operators in Python are:

OperatorNameDescription
+AdditionAdds two values
-SubtractionSubtracts the second value from the first
*MultiplicationMultiplies two values
/DivisionDivides the first value by the second (returns a float)
%ModuloReturns the remainder of the division of the first value by the second
**ExponentiationRaises the first value to the power of the second
//Integer DivisionDivides the first value by the second and returns the integer part

If you want to learn more, check out the Introduction to Programming Course

List of Arithmetic Operators

Addition +

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
Copied!

Subtraction -

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

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

Multiplication *

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

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

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
Copied!

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
Copied!

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
Copied!

Exponentiation **

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

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