Strings
Python ↔ Baobab
20 correspondences
All the usual str methods exist in Bao with the same dotted syntax. F-strings work identically: f"Bonjour {nom}".
| Python | Baobab | Description |
|---|---|---|
| s.upper() | s.majuscules() | Return the string in UPPERCASE. |
| s.lower() | s.minuscules() | Return the string in lowercase. |
| s.capitalize() | s.capitaliser() | Capitalize the first letter. |
| s.title() | s.titre() | Capitalize each word. |
| s.strip() | s.rogner() | Remove leading and trailing whitespace. |
| s.lstrip() / s.rstrip() | s.rogner_gauche() / s.rogner_droite() | Strip whitespace on the left / right. |
| s.replace(a, b) | s.remplacer(a, b) | Replace every occurrence of a with b. |
| s.split(sep) | s.decouper(sep) | Split the string into a list of parts. |
| sep.join(liste) | sep.joindre(liste) | Join a list of strings with a separator. |
| s.find(sub) | s.trouver(sub) | Index of the first occurrence (-1 if missing). |
| s.index(sub) | s.indice(sub) | Like find, but raises an error if missing. |
| s.count(sub) | s.compter(sub) | Number of occurrences of the substring. |
| s.startswith(p) | s.commence_par(p) | True if the string starts with p. |
| s.endswith(p) | s.finit_par(p) | True if the string ends with p. |
| s.isdigit() | s.est_numerique() | True if all characters are digits. |
| s.isalpha() | s.est_alphabetique() | True if all characters are letters. |
| s.center(n) / s.zfill(n) | s.centrer(n) / s.remplir_zeros(n) | Center the string / pad with zeros. |
| f"…{x}…" | f"…{x}…" | Formatted string — expression interpolation. |
| s[0], s[-1], s[1:4] | s[0], s[-1], s[1:4] | Indexing and slicing, identical to Python. |
| len(s) | longueur(s) | Number of characters. |
Complete example — Baobab ↔ Python
Baobab
12345678910111213141516phrase = " le baobab est majestueux "
propre = phrase.rogner()
afficher(propre.majuscules()) # → LE BAOBAB EST MAJESTUEUX
afficher(propre.titre()) # → Le Baobab Est Majestueux
afficher(propre.remplacer("majestueux", "géant"))
afficher(propre.compter("a")) # → 3
afficher(propre.commence_par("le")) # → vrai
mots = propre.decouper(" ")
afficher(mots) # → ["le", "baobab", "est", "majestueux"]
afficher("-".joindre(mots)) # → le-baobab-est-majestueux
nom = "Aminata"
afficher(f"Bonjour {nom}, ton nom a {longueur(nom)} lettres !")
afficher(nom[0] + nom[-1]) # → Aa
afficher(nom[1:4]) # → minPython
12345678910111213141516phrase = " le baobab est majestueux "
propre = phrase.strip()
print(propre.upper()) # → LE BAOBAB EST MAJESTUEUX
print(propre.title()) # → Le Baobab Est Majestueux
print(propre.replace("majestueux", "géant"))
print(propre.count("a")) # → 3
print(propre.startswith("le")) # → True
mots = propre.split(" ")
print(mots) # → ["le", "baobab", "est", "majestueux"]
print("-".join(mots)) # → le-baobab-est-majestueux
nom = "Aminata"
print(f"Bonjour {nom}, ton nom a {len(nom)} lettres !")
print(nom[0] + nom[-1]) # → Aa
print(nom[1:4]) # → min