Python Operators
Operators are used to perform operations on variables and values.
I. Python Arithmetic operators
| Operation | Description |
|---|---|
| x + y | Addition |
| x - y | Subtraction |
| x * y | Multipication |
| x / y | Division -> result is float |
| x // y | Division -> result is int |
| x % y | Remainder of x / y for positive x, y |
| x ** y | x to the power y |
II. Python Comparison operators
They can be created by comparing values by using the rational operators
- Equal: ==.
- Not equal: !=
- Greater than: >
- Less than: <
- Greater than or equal to: >=
- Less than or equal to: <=
III. Python Logical operation
- and
- or
- not
IV. Python Membership Operators
We can use membership operators to test if a sequence is presented in an object:
- in
- not in For example
>>> x = 2
>>> y = [2,4]
>>> x in y
True