Python – La méthode String title()
La méthode title() renvoie une chaîne dans laquelle le premier caractère de chaque mot est en majuscule. Comme un en-tête ou un titre. Si le mot contient un nombre ou un symbole, la première lettre qui suit sera convertie en majuscules.
Syntaxe:
string.title()
Paramètres:
La méthode title() ne prend aucun paramètre.
Valeur de retour:
La méthode title() renvoie une chaîne dans laquelle le premier caractère de chaque mot est en majuscule.
Exemple 1:
str = "welcome to waytolearnx!" res = str.title() print(res)
Sortie:
Welcome To Waytolearnx!
Exemple 2:
str = "hello 3world!" res = str.title() print(res)
Sortie:
Hello 3World!