pythontitle-case

How to convert string to Title Case in Python?


Is there a library or standard way to perform this task?

Example:

HILO -> Hilo
new york -> New York
SAN FRANCISCO -> San Francisco

Solution

  • Why not use title Right from the docs:

    >>> "they're bill's friends from the UK".title()
    "They'Re Bill'S Friends From The Uk"
    

    If you really wanted PascalCase you can use this:

    >>> ''.join(x for x in 'make IT pascal CaSe'.title() if not x.isspace())
    'MakeItPascalCase'