Python String istitle ()

Ak je reťazec reťazcom obsahujúcim názov, vráti istitle () hodnotu True. Ak nie, vráti hodnotu False.

Syntax istitle()metódy je:

 string.istitle ()

istitle () parametre

istitle()Metóda neberie žiadne parametre.

Návratová hodnota z istitle ()

Tieto istitle()metóda vráti:

  • True ak je reťazec reťazcom obsahujúcim názov
  • False ak reťazec nie je reťazec s titulkom alebo prázdny reťazec

Príklad 1: Práca 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())

Výkon

 True False True True False

Príklad 2: Ako používať 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')

Výkon

 Názov reťazca Nie je reťazec s názvom

Zaujímavé články...