.title()
The .title()
string method takes in a string and returns a copy of the string formatted in the title case: each word in the string is capitalized.
Syntax
string.title()
Example 1
Use .title()
to format a string in title case:
my_string = "Codecademy docs"print(my_string.title())# Output: Codecademy Docs
Example 2
Use .title()
to format author_name
in title case:
author_name = "jane smith"print(author_name.title())# Output: Jane Smith
Codebyte Example
Use .title()
to format the string my_string
in title case: