Built-in functions

Python ↔ Baobab
20 correspondences

The built-in library covers everyday Python builtins: printing, input, aggregates, sorting, functional transformation.

PythonBaobabDescription
print(x)afficher(x)Print one or more values.
print(a, b, sep="-", end="")afficher(a, b, separateur="-", fin="")Choose the separator and the line ending.
input(msg)lire(msg)Read a string typed by the user.
len(x)longueur(x)Size of a sequence or collection.
range(...)intervalle(...)Number sequence for loops.
sum(l)somme(l)Sum of items.
min(l) / max(l)min(l) / max(l)Smallest / largest value (already French!).
abs(x)absolu(x)Absolute value.
round(x, n)arrondir(x, n)Round to n decimal places.
pow(a, b)puissance(a, b)a raised to the power b.
sorted(l)trie(l)New sorted list, original untouched.
sorted(l, key=f)trie(l, cle=f)Sort by the key computed by f (e.g. cle=longueur).
reversed(l)inverse(l)Iterator in reverse order.
enumerate(l)enumerer(l)(index, item) pairs.
zip(a, b)zip(a, b)Combine several sequences in parallel.
map(f, l)appliquer(f, l)Apply a function to every item.
filter(f, l)filtrer(f, l)Keep items for which f is true.
all(l)tous(l)True if every item is truthy.
any(l)au_moins_un(l)True if at least one item is truthy.
open(...)ouvrir(...)Open a file (see the Files section).
Complete example — Baobab ↔ Python
Baobab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
notes = [12, 15, 8, 18, 10] afficher(somme(notes)) # → 63 afficher(min(notes), max(notes)) # → 8 18 afficher(arrondir(somme(notes) / longueur(notes), 1)) # → 12.6 afficher(trie(notes)) # → [8, 10, 12, 15, 18] afficher(liste(inverse(notes))) # → [10, 18, 8, 15, 12] doublees = liste(appliquer(lambda n: n * 2, notes)) afficher(doublees) # → [24, 30, 16, 36, 20] reussies = liste(filtrer(lambda n: n >= 10, notes)) afficher(reussies) # → [12, 15, 18, 10] afficher(tous(n > 0 pour n dans notes)) # → vrai afficher(au_moins_un(n == 18 pour n dans notes)) # → vrai afficher(absolu(-7)) # → 7 afficher(puissance(2, 8)) # → 256 mots = ["figue", "ao", "goyave"] afficher(trie(mots, cle=longueur)) # → ['ao', 'figue', 'goyave'] afficher("fin", "de", "ligne", separateur="-", fin=".\n")
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
notes = [12, 15, 8, 18, 10] print(sum(notes)) # → 63 print(min(notes), max(notes)) # → 8 18 print(round(sum(notes) / len(notes), 1)) # → 12.6 print(sorted(notes)) # → [8, 10, 12, 15, 18] print(list(reversed(notes))) # → [10, 18, 8, 15, 12] doublees = list(map(lambda n: n * 2, notes)) print(doublees) # → [24, 30, 16, 36, 20] reussies = list(filter(lambda n: n >= 10, notes)) print(reussies) # → [12, 15, 18, 10] print(all(n > 0 for n in notes)) # → True print(any(n == 18 for n in notes)) # → True print(abs(-7)) # → 7 print(pow(2, 8)) # → 256 mots = ["figue", "ao", "goyave"] print(sorted(mots, key=len)) # → ['ao', 'figue', 'goyave'] print("fin", "de", "ligne", sep="-", end=".\n")