Python program to capitalize first letter of each words of a string

Python program to capitalize first letter of each words of a string :

In this tutorial, we will learn how to capitalize the first letter of each words in a string. The user will enter the string. Our program will save it in a variable . Then using .title() method, we will convert the first letter of each words to capital and save the string in a different variable. Finally, print out the result . Let’s take a look at the program :

Python program to capitalize first letter of each words :

input_string = input("Enter a string : ")

output_string = input_string.title()

print("Output String : ",output_string)

Sample Output :

Enter a string : hello world
Output String :  Hello World

Enter a string : this is a line without any capital letter
Output String :  This Is A Line Without Any Capital Letter

Leave a Reply