Skip to content

Arithmetic operators in Python

  • by

Python arithmetic operators perform mathematical operations like addition, subtraction, multiplication, etc. Let’s understand the following:-

OperatorMeaningExample
+Add two operands or unary plusx + y+ 2
Subtract the right operand from the left or unary minusx – y- 2
*Multiply two operandsx * y
/Divide the left operand by the right one (always results in float)x / y
%Modulus – the remainder of the division of the left operand by the rightx % y (remainder of x/y)
//Floor division – division that results in the whole number adjusted to the left in the number linex // y
**Exponent – left operand raised to the power of rightx**y (x to the power y)

Arithmetic operators in Python

A simple example code shows the basic arithmetic operations i.e. Arithmetic operators are used with numeric values to perform common mathematical operations:

x = 15
y = 5

print('x + y =', x + y)

print('x - y =', x - y)

print('x * y =', x * y)

print('x / y =', x / y)

print('x // y =', x // y)

print('x ** y =', x ** y)

Output:

Arithmetic operators in Python

These operators can be combined and used in expressions to perform more complex calculations. Additionally, parentheses can be used to specify the order of operations (precedence) when needed.

Do comment if you have any doubts or suggestions on this Python operators topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading