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 == 5 ➔ True
!=Not equal5 != 3 ➔ True
<Less than3 < 5 ➔ True
<=Less than or equal3 <= 3 ➔ True
>Greater than5 > 3 ➔ True
>=Greater than or equal5 >= 5 ➔ True

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 False ➔ False
orTrue if either side is TrueTrue or False ➔ True
notInverts the boolean valuenot True ➔ False, not False ➔ True

Modulo Operator​

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