Istitle () restituisce True se la stringa è una stringa titolata. In caso contrario, restituisce False.
La sintassi del istitle()
metodo è:
string.istitle ()
istitle () Parametri
Il istitle()
metodo non accetta parametri.
Valore restituito da istitle ()
Il istitle()
metodo restituisce:
True
se la stringa è una stringa titolataFalse
se la stringa non è una stringa contenente un titolo o una stringa vuota
Esempio 1: funzionamento di 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())
Produzione
Vero Falso Vero Vero Falso
Esempio 2: come usare 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')
Produzione
Titlecased String Non è una stringa titolata