Skip to main content

Operators in Python

Operators allow you to perform calculations, compare values, and build logic in the code.

Arithmetic

OperatorActionExample
+Addition2 + 3
-Subtraction5 - 1
*Multiplication4 * 2
/Division6 / 2
//Floor division7 // 2
%Modulus8 % 3
**Exponentiation2 ** 3

Comparison

OperatorMeaningExample
==Equal tox == y
!=Not equal tox != y
<Less thanx < y
>Greater thanx > y
<=Less than or equal tox <= y
>=Greater than or equal tox >= y

Logical

OperatorMeaningExample
andLogical ANDTrue and False
orLogical ORFalse or True
notLogical NOTnot True