1. The different types of operators in Python
Operators are used in Python to perform operations on variables and associated values.
Python classifies operators according to the following groups:
- Arithmetic operators
- Assignment operators
- Comparison operators
- Logical operators
2. Arithmetic operators
Arithmetic operators are used in Python to perform calculation operations on variables such as addition, multiplication, division...
Opérateur | Description |
+ | Addition |
- | Soustraction |
* | Multiplication |
/ | Division |
% | Modulo (rest of Euclidean division) |
** | Exponentiation |
// | quotient of the Euclidean division |
3. Assignment operators
Assignment operators are used in Python to assign values to variables:
Operators | Example | Explanation |
= | x = 7 | x = 7 |
+ = | x + = 5 | x = x + 5 |
- = | x - = 5 | x = x -5 |
* = | x * = 5 | x = x *5 |
/ = | x / = 5 | x = x / 5 |
% = | x % = 5 | x = x %5 |
// = | x // = 5 | x = x //5 |
** = | x ** = 5 | x = x **5 |
& = | x & = 5 | x = x &5 |
4. Comparison operators
Comparison operators are used in Python to compare variables:
Operators | Description |
= = | Equality operator |
!= | Different operator |
> | Superior |
< | Inferior |
>= | Greater than or equal |
<= | Less than or equal |
5. Logical operators
Opérateurs | Description |
and | and logic : returns T rue if both instructions are true and False if not |
or | or logic: returns True if at least one of the statements is true and False if not |
not | Negation returns False if the assertion is True |
Younes Derfoufi
CRMEF OUJDA