Convert String to Title Case in Python
Same as .title() on the previous page, printed in one line. McDonald still becomes Mcdonald.
BeginnerString ProgramsExample 12 of 25
convert-string-to-title-case.py
Run in browser1# Program to convert string to title case23s = input("Enter a sentence: ")45print("Title case:", s.title())
Output
Enter a sentence: python STRING programs Title case: Python String Programs
What's going on
s.title() again. Previous program stored it in result. This one prints it immediately. Same quirk: McDonald becomes Mcdonald.
If you need real title case for names, this is the wrong function.