Tuples

Python ↔ Baobab
6 correspondences

Immutable sequences, optional parentheses, multiple unpacking — just like Python.

PythonBaobabDescription
t = (1, 2, 3)t = (1, 2, 3)Create a tuple.
x, y = 1, 2x, y = 1, 2Multiple assignment by unpacking.
a, b = b, aa, b = b, aSwap 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
1
2
3
4
5
6
7
8
9
10
11
12
point = (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)) # → 3
Python
1
2
3
4
5
6
7
8
9
10
11
12
point = (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