Operators
Updated Oct 28, 2019 ·
Arithmetic Operators
Python uses standard and special operators for math operations.
Operator | Description | Example |
---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / 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).
Operator | Description | Example |
---|---|---|
== | Equal | 5 == 5 → True |
!= | Not equal | 5 != 3 → True |
< | Less than | 3 < 5 → True |
<= | Less than or equal | 3 <= 3 → True |
> | Greater than | 5 > 3 → True |
>= | Greater than or equal | 5 >= 5 → True |
Logical Operators
Logical operators are used to combine conditional statements and determine the truth value of expressions.
Operator | Description | Example |
---|---|---|
and | True if both sides are True | True and False → False |
or | True if either side is True | True or False → True |
not | Inverts the boolean value | not True → False , not False → True |
Modulo Operator
Modulo Operator (%
) returns the remainder of division.
Example: 5 % 2
returns 1
.