In this tutorial, we’ll learn what Python string istitle() method is and how to properly use it. We’ll go through multiple Python code examples to understand how istitle() method works in Python.
Introduction: Python String istitle() Method
This method will return True if the string is in title-cased format and will return False, if its empty or not in title-cased format.
Syntax of istitle() Method
string.istitle()
- Python string istitle() method does not take any arguments.
- It returns True if a string is in title-cased format and returns False, if its not title-cased or empty.
Example 1: istitle() Method applied on a Python String
strVal='This Is Python Programming Language' print(strVal.istitle())
Output
True
Python string istitle() method return True as the specified string is in title-cased format.
See below examples as well to properly understand how istitle() method works.
print('This Is Python-3 Language'.istitle()) print('This Is Python3 Language'.istitle()) print('This Is @ Python-3 Language'.istitle()) print('This Is Python 3'.istitle()) print('PYTHON PROGRAMMING'.istitle()) print('PYTHON'.istitle()) print('PYTHON Program'.istitle()) print(''.istitle()) // empty string
Output
True True True True False False False False
Example 2: istitle() Method in Python If Else Condition
// can use a simple string as well(not using special characters or numbers) val='Python-3 Is @ Programming Language.' if val.istitle(): print('Its a valid title-cased format') else: print('Its an invalid title-cased format')
Output
Its a valid title-cased format
Python string istitle method return True as the specified string is in a valid title-cased format.
Example 3: istitle() Method Return Value
val='Python Is A Programming Lanuage' returnedVal=val.istitle() print(returnedVal)
Output
True
Conclusion
To conclude this tutorial, hope you now have an in-depth practical knowledge of how to easily and properly use Python string istitle method. I’ll be looking forward to receive your valuable feedback on this post. Thank you for reading it.