Python String istitle ()

Le istitle () renvoie True si la chaîne est une chaîne titrée. Sinon, il renvoie False.

La syntaxe de la istitle()méthode est:

 string.istitle ()

Paramètres istitle ()

La istitle()méthode ne prend aucun paramètre.

Valeur renvoyée par istitle ()

La istitle()méthode renvoie:

  • True si la chaîne est une chaîne titrée
  • False si la chaîne n'est pas une chaîne titrée ou une chaîne vide

Exemple 1: Fonctionnement de istitle ()

 s = 'Python Is Good.' print(s.istitle()) s = 'Python is good' print(s.istitle()) s = 'This Is @ Symbol.' print(s.istitle()) s = '99 Is A Number' print(s.istitle()) s = 'PYTHON' print(s.istitle())

Production

 Vrai Faux Vrai Vrai Faux

Exemple 2: Comment utiliser istitle ()?

 s = 'I Love Python.' if s.istitle() == True: print('Titlecased String') else: print('Not a Titlecased String') s = 'PYthon' if s.istitle() == True: print('Titlecased String') else: print('Not a Titlecased String')

Production

 Chaîne titrée pas une chaîne titrée

Articles intéressants...