Introduction à Python pour les développeurs
Jasmin Ludolf
Senior Data Science Content Developer
# Boolean variable
the_truth = True
print(the_truth)
True
Opérateurs de comparaison
Vérifier si deux éléments sont égaux
==# Compare if 2 is equal to 3
2 == 3
False
# Check that 2 is not equal to 3
2 != 3
True
# Is 5 less than 7?
5 < 7
True
# Is 5 less than or equal to 7?
5 <= 7
True
# Is 5 greater than 7?
5 > 7
False
# Is 5 greater or equal to 7?
5 >= 7
False
# Is James greater than Brian
"James" > "Brian"
True
if (si) la condition est remplie, effectuer l'action, sinon ignorer# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity
if (si) la condition est remplie, effectuer l'action, sinon ignorer# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:
if (si) la condition est remplie, effectuer l'action, sinon ignorer# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")
# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!") # This line is not indented
print("You have enough pasta!")
^
IndentationError: expected an indented block
# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")
elif s que nous le souhaitons !# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")# Otherwise... else: print("Not enough pasta.")
Not enough pasta.
| Opérateur | Fonction |
|---|---|
== |
Égal à |
!= |
N'est pas égal à |
> |
Supérieur à |
>= |
Supérieur ou égal à |
< |
Inférieur à |
<= |
Inférieur ou égal à |
| Mot-clé | Fonction | Utilisation |
|---|---|---|
if |
Si la condition est remplie | En premier dans le flux de travail |
elif |
Sinon, vérifier si la condition est remplie | Après if |
else |
Sinon, effectuer cette action | Après elif |
Introduction à Python pour les développeurs