Skip to main content

Operators

Updated Oct 28, 2019 ·

Arithmetic Operators

Python uses standard and special operators for math operations.

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
**Exponentiation (power)a ** b (e.g., a ** 2 for square)
//Integer division (quotient)a // b
%Modulus (remainder)a % b

Comparison Operators

Comparison operators return boolean results (True/False).

OperatorDescriptionExample
==Equal5 == 5True
!=Not equal5 != 3True
<Less than3 < 5True
<=Less than or equal3 <= 3True
>Greater than5 > 3True
>=Greater than or equal5 >= 5True

Logical Operators

Logical operators are used to combine conditional statements and determine the truth value of expressions.

OperatorDescriptionExample
andTrue if both sides are TrueTrue and FalseFalse
orTrue if either side is TrueTrue or FalseTrue
notInverts the boolean valuenot TrueFalse, not FalseTrue

Modulo Operator

Modulo Operator (%) returns the remainder of division. Example: 5 % 2 returns 1.