Write a program to accept a string in lowercase.convert all the first letters of the words in the uppercase and display the new string
Answers
Answer:
Here two way
1:-
s = input("Enter your String: ")
stringList = s.split()
stringList = [word[0].upper() + word[1:] for word in s.split()]
s = " ".join(stringList)
print(s)
#But this is very long way and we need to type too much and we like less typeing and result is high. So i prefered second way that is.
2a:-
s = " ".join([word[0].upper() + word[1:] for word in input().split()])
#in this code string is changed at the time taking input. But if you want store your input you can go with blow code.
2b:-
s1 = input()
s2 = " ".join([word[0].upper() + word[1:] for word in s1.split()])
Explanation:
In above question I am using split() method that split a string into chunk of words and strore every word as element of a list.
After that I convert first letter of every word(or element of list) in uppercase