Modules & bibliothèque standard
Python ↔ Baobab
11 correspondances
importer/depuis traduisent import/from. La bibliothèque standard francise les modules essentiels : maths pour math, aleatoire pour random.
| Python | Baobab | Description |
|---|---|---|
| import math | importer maths | Importe le module mathématique. |
| from math import sqrt | importer racine depuis maths | Importe une seule fonction du module. |
| math.sqrt(x) | maths.racine(x) | Racine carrée. |
| math.pi | maths.pi | La constante π. |
| math.floor(x) / math.ceil(x) | maths.plancher(x) / maths.plafond(x) | Arrondi à l'entier inférieur / supérieur. |
| import random | importer aleatoire | Importe le module de hasard. |
| random.randint(a, b) | aleatoire.entier(a, b) | Entier aléatoire entre a et b inclus. |
| random.choice(l) | aleatoire.choix(l) | Élément tiré au hasard dans une liste. |
| random.shuffle(l) | aleatoire.melanger(l) | Mélange une liste sur place. |
| random.random() | aleatoire.nombre() | Décimal aléatoire entre 0 et 1. |
| import utils (fichier local) | importer utils depuis "./utils.bao" | Importe un module de votre projet. |
Exemple complet - Baobab ↔ Python
Baobab
1234567891011121314151617181920importer 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
1234567891011121314151617181920import 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))