istitle() string method in Python
The istitle() string method returns True if the string is in title case:
- First letter of each word is uppercase
- All other letters are lowercase
- Returns False otherwise.
- There must be at least one character in the string.
Syntax
Python Syntax
string.istitle()
Example:
Python
text1 = "Hello World" print(text1.istitle()) # Output: True # Both words start with uppercase, rest lowercase text2 = "Hello world" print(text2.istitle()) # Output: False # 'world' does not start with uppercase text3 = "HELLO WORLD" print(text3.istitle()) # Output: False # All uppercase is NOT title case text4 = "123 Python" print(text4.istitle()) # Output: True # Numbers are ignored; Python starts with uppercase
Special Notes
- Only considers cased characters (letters) for title-case rules.
- Works well for checking proper capitalization in sentences or headings.