istitle()

my_str.istitle()
Returns True if all words in a string starts with upper case letter , otherwise returns False
my_str='Welcome To Python'
print(my_str.istitle())      # Output is True 

my_str='Welcome to Python'
print(my_str.istitle())      # Output is False

my_str='WELCOME TO PYTHON'
print(my_str.istitle())      # Output is False ( All letters in Upper case )

my_str='Welcome to python'              
print(my_str.istitle())      # False ( All words are not starting with upper case)

my_str='100 Welcome'              
print(my_str.istitle())     # True 

Example 1: Handling Special Characters

my_str = "123 Welcome"
print(my_str.istitle())  # Output: True (numbers don't affect title case)

Example 2: Validating User Input

title = input("Enter title: ")
if title.istitle():
    print("Title is correctly formatted")
else:
    print("Incorrect title format")

Example 3: Mixed Case Words

my_str = "Hello World"
print(my_str.istitle())  # Output: True

my_str = "hello World"
print(my_str.istitle())  # Output: False (First word is lowercase)

Example 4: Title with Special Characters

my_str = "Python@3 Rocks!"
print(my_str.istitle())  # Output: True (Special characters are ignored)

my_str = "Python@rocks"
print(my_str.istitle())  # Output: False (Rocks is not title-cased)

Example 5: Empty String

empty_str = ""
print(empty_str.istitle())  # Output: False


All String methods


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer