Python — Operators

Catégorie Opérateur Exemple Résultat / Description
Arithmétique + 5 + 2 7 — Addition
Arithmétique - 5 - 2 3 — Soustraction
Arithmétique * 5 * 2 10 — Multiplication
Arithmétique / 5 / 2 2.5 — Division
Arithmétique // 5 // 2 2 — Division entière
Arithmétique % 5 % 2 1 — Modulo / reste
Arithmétique ** 5 ** 2 25 — Puissance
Comparaison == 5 == 5 True — Égal
Comparaison != 5 != 3 True — Différent
Comparaison < 3 < 5 True — Inférieur
Comparaison > 5 > 3 True — Supérieur
Comparaison <= 5 <= 5 True — Inférieur ou égal
Comparaison >= 5 >= 5 True — Supérieur ou égal
Logique and True and False False — ET logique
Logique or True or False True — OU logique
Logique not not True False — Négation
Affectation = x = 5 Affecte une valeur
Affectation += x += 2 x = x + 2
Affectation -= x -= 2 x = x - 2
Affectation *= x *= 2 x = x * 2
Affectation /= x /= 2 x = x / 2
Affectation //= x //= 2 x = x // 2
Affectation %= x %= 2 x = x % 2
Affectation **= x **= 2 x = x ** 2
Bit à bit & a & b ET bit à bit
Bit à bit \| a \| b OU bit à bit
Bit à bit ^ a ^ b XOR bit à bit
Bit à bit ~ ~a Complément bit à bit
Bit à bit << a << 2 Décalage vers la gauche
Bit à bit >> a >> 2 Décalage vers la droite
Appartenance in 3 in [1, 2, 3] True — Élément présent
Appartenance not in 4 not in [1, 2, 3] True — Élément absent
Identité is a is b Même objet en mémoire
Identité is not a is not b Objets différents