Python String istitle ()

Funkcja istitle () zwraca wartość True, jeśli łańcuch jest łańcuchem zamkniętym w tytule. Jeśli nie, zwraca False.

Składnia istitle()metody to:

 string.istitle ()

istitle () Parametry

istitle()Metoda nie ma żadnych parametrów.

Wartość zwracana z istitle ()

Te istitle()metody powraca:

  • True jeśli ciąg jest łańcuchem o nazwie
  • False jeśli ciąg nie jest ciągiem zawierającym tytuł lub ciągiem pustym

Przykład 1: Działanie 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())

Wynik

 True False True True False

Przykład 2: Jak używać funkcji 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')

Wynik

 Ciąg o nazwie nie jest ciągiem o nazwie

Interesujące artykuły...