Modules & standard library

Python ↔ Baobab
11 correspondences

importer/depuis translate import/from. The standard library frenchifies the essential modules: maths for math, aleatoire for random.

PythonBaobabDescription
import mathimporter mathsImport the math module.
from math import sqrtimporter racine depuis mathsImport a single function from a module.
math.sqrt(x)maths.racine(x)Square root.
math.pimaths.piThe constant π.
math.floor(x) / math.ceil(x)maths.plancher(x) / maths.plafond(x)Round down / up to the nearest integer.
import randomimporter aleatoireImport the randomness module.
random.randint(a, b)aleatoire.entier(a, b)Random integer between a and b inclusive.
random.choice(l)aleatoire.choix(l)Random element from a list.
random.shuffle(l)aleatoire.melanger(l)Shuffle a list in place.
random.random()aleatoire.nombre()Random float between 0 and 1.
import utils (fichier local)importer utils depuis "./utils.bao"Import a module from your project.
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
importer maths importer aleatoire afficher(maths.racine(144)) # → 12.0 afficher(maths.pi) # → 3.141592653589793 afficher(maths.plancher(3.9)) # → 3 afficher(maths.plafond(3.1)) # → 4 tirage = aleatoire.entier(1, 6) afficher(f"Le dé donne {tirage}") equipe = ["Amina", "Kofi", "Fatou"] capitaine = aleatoire.choix(equipe) aleatoire.melanger(equipe) afficher(f"Capitaine : {capitaine}") afficher(f"Ordre de passage : {equipe}") # Module local du projet importer utils depuis "./utils.bao" afficher(utils.additionner(2, 3))
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import math import random print(math.sqrt(144)) # → 12.0 print(math.pi) # → 3.141592653589793 print(math.floor(3.9)) # → 3 print(math.ceil(3.1)) # → 4 tirage = random.randint(1, 6) print(f"Le dé donne {tirage}") equipe = ["Amina", "Kofi", "Fatou"] capitaine = random.choice(equipe) random.shuffle(equipe) print(f"Capitaine : {capitaine}") print(f"Ordre de passage : {equipe}") # Local project module import utils print(utils.additionner(2, 3))