import re def titlecase(s): return re.sub(r"[A-Za-z]+('[A-Za-z]+)?", lambda mo: mo.group(0).capitalize(), s)
string = 'this will be title case' print(string.title()) #output: 'This Will Be Title Case'