Language: EN

python-operadores-aritmeticos

Arithmetic Operators in Python

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

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

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

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

Floor Division (//)

The floor 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

Modulus (%)

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

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

Exponentiation (**)

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

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