Python String istittle() method
Python String istittle() method
The string.istittle() method returns a boolean value true if the string is a titlecased string and there is at least one character, for example uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return false otherwise.
Syntax
string.istitle()
Parameter
NA
Return
This method returns a Boolean value True if the string is a titlecased string else it returns False.
Example 1
# Python program explaining # the istitle() method # In the given string the first character in each word is # uppercase and remaining all are in lowercases string = "My Favourite Teacher" print("String 1:",string) # will return true print("The above string is Titlecased:",string.istitle()) # First character in first word is lowercase string = "geeks For Geeks" print("String 2:",string) print("The above string is Titlecased:",string.istitle()) # Third word has uppercase # characters at middle string = "My favourite TEACHER" print("String 3:",string) print("The above string is Titlecased:",string.istitle()) # paasing the first word as integer and in rest the first character in each word is # uppercase and remaining all are in lowercases string = "6041 Is My Lucky Number" print("String 4:",string) print("The above string is Titlecased:",string.istitle()) # All the characters are in uppercase string = "TUTORIALS" print("String 5:",string) print("The above string is Titlecased:",string.istitle())
Output
String 1: My Favourite Teacher The above string is Titlecased: True String 2: geeks For Geeks The above string is Titlecased: False String 3: My favourite TEACHER The above string is Titlecased: False String 4: 6041 Is My Lucky Number The above string is Titlecased: True String 5: TUTORIALS The above string is Titlecased: False
Example 2
# Python program explaining # the istitle() method string = "I Love Python Programming" print("String 1:",string) # validating if else condition if string.istitle() == True: print('The above string is Titlecased\n') else: print('The above string is Not a Titlecased String\n') string = "I love Python programing" print("String 2:",string) # validating if else condition if string.istitle() == True: print('The above string is Titlecased') else: print('The above string is Not a Titlecased String')
Output
String 1: I Love Python Programming The above string is Titlecased String 2: I love Python programing The above string is Not a Titlecased String