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

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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.