Check sibling questions

Write a program that takes a string with multiple words and capitalizes the first letter of each word and forms a new string out of it.



Untitled 34.jpg


str=input( "Enter a string: " )


i= 0

str2= ""

while i<l:

    if i == 0 :

        str2 = str2+str[i].upper()

    elif str[i]== ' ' and str[i+ 1 ]!= ' ' :


        str2=str2+str[i+ 1 ].upper()

        i=i+ 1


        str2 = str2+str[i]

    i=i+ 1

print( "New string: " +str2) 



The first letter of the string and every letter after a blank space is converted to uppercase using the upper( ) method.

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.