I got most of the code down but I am having issues getting the string to space back out after making the first letter of each word uppercase
here's what I have so far:
message = input('Write a short message.')
new_message = message.split()
glue = ""
for item in new_message:
glue = item[0].upper() item[1:]
print(glue)
CodePudding user response:
try with:
message.capitalize()
CodePudding user response:
If you want to capitalize each word you can try capitalize() and the code will look like this:
message = input('Write a short message.')
new_message = message.split()
cap_message = [x.capitalize() for x in new_message]
print(cap_message)
- message.split() - split the string into a list using default separator which is any whitespace. The result is a list of words.
- capitalize each word in the list using List Comprehention. The list of capitalized words is saved in cap_message variable for code clarity.
- print the list of capitalized words