Conditions
Python ↔ Baobab
7 correspondences
si / sinonsi / sinon mirror if / elif / else, with the same indentation rule and the same colon.
| Python | Baobab | Description |
|---|---|---|
| if cond: | si cond: | Branch executed when the condition is true. |
| elif cond: | sinonsi cond: | Alternative condition tested next. |
| else: | sinon: | Default branch. |
| if a and b or not c: | si a et b ou non c: | Combining logical operators. |
| a if cond else b | a si cond sinon b | One-expression ternary. |
| if x in liste: | si x dans liste: | Membership condition. |
| if not liste: | si non liste: | True when the list is empty (falsy values). |
Complete example — Baobab ↔ Python
Baobab
12345678910111213141516age = 17
permis = faux
si age >= 18 et permis:
afficher("Peut conduire")
sinonsi age >= 18:
afficher("Doit passer le permis")
sinon:
afficher("Trop jeune") # ← exécuté
categorie = "adulte" si age >= 18 sinon "mineur"
afficher(categorie) # → mineur
panier = []
si non panier:
afficher("Panier vide") # ← exécutéPython
12345678910111213141516age = 17
permis = False
if age >= 18 and permis:
print("Peut conduire")
elif age >= 18:
print("Doit passer le permis")
else:
print("Trop jeune") # ← executed
categorie = "adulte" if age >= 18 else "mineur"
print(categorie) # → mineur
panier = []
if not panier:
print("Panier vide") # ← executed