Capitalize the first letter of each word in a String in Python
In this tutorial, we are going to learn about how to capitalize or uppercase the first letter of a each word in a given string in Python.
Consider, we have a following string:
a = "how are you python"
Now we need to capitalize the first letter of each word in the above string like this:
How Are You Python
Using the title() method
To capitalize the first letter of each word in a string, we can use the built-in title()
method in Python.
Here is an example:
a = "how are you python"
print(a.title())
Output:
How Are You Python