Tuples
Python ↔ Baobab
6 correspondences
Immutable sequences, optional parentheses, multiple unpacking — just like Python.
| Python | Baobab | Description |
|---|---|---|
| t = (1, 2, 3) | t = (1, 2, 3) | Create a tuple. |
| x, y = 1, 2 | x, y = 1, 2 | Multiple assignment by unpacking. |
| a, b = b, a | a, b = b, a | Swap two variables in one line. |
| t.count(x) / t.index(x) | t.compter(x) / t.indice(x) | The only two tuple methods. |
| tuple([1, 2]) | tuple([1, 2]) | List → tuple conversion. |
| len(t), t[0], t[1:] | longueur(t), t[0], t[1:] | Length, indexing, slicing. |
Complete example — Baobab ↔ Python
Baobab
123456789101112point = (3, 5)
x, y = point # dépaquetage
afficher(f"x={x}, y={y}") # → x=3, y=5
a, b = 1, 2
a, b = b, a # échange
afficher(a, b) # → 2 1
couleurs = ("rouge", "vert", "rouge")
afficher(couleurs.compter("rouge")) # → 2
afficher(couleurs.indice("vert")) # → 1
afficher(longueur(couleurs)) # → 3Python
123456789101112point = (3, 5)
x, y = point # unpacking
print(f"x={x}, y={y}") # → x=3, y=5
a, b = 1, 2
a, b = b, a # swap
print(a, b) # → 2 1
couleurs = ("rouge", "vert", "rouge")
print(couleurs.count("rouge")) # → 2
print(couleurs.index("vert")) # → 1
print(len(couleurs)) # → 3