Python Exercises: Capitalize the first letter and lowercases the rest
Capitalize first letter of words.
Write a Python program that capitalizes the first letter and lowercases the remaining letters in a given string.
Sample Data:
(“Red Green WHITE) -> “Red Green White”
(“w3resource”) -> “W3resource”
(“dow jones industrial average”) -> “Dow Jones Industrial Average”
Sample Solution-1:
Python Code:
Sample Output:
Original string: Red Green WHITE Capitalize the first letter and lowercases the rest: Red Green White Original string: w3resource Capitalize the first letter and lowercases the rest: W3resource Original string: dow jones industrial average Capitalize the first letter and lowercases the rest: Dow Jones Industrial Average
Flowchart:
Sample Solution-2:
Python Code:
Sample Output:
Original string: Red Green WHITE Capitalize the first letter and lowercases the rest: Red Green White Original string: w3resource Capitalize the first letter and lowercases the rest: W3resource Original string: dow jones industrial average Capitalize the first letter and lowercases the rest: Dow Jones Industrial Average
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to capitalize the first letter of each word in a string and lowercase the remaining letters using title().
- Write a Python program to split a sentence into words, capitalize the first letter of each, and join them back into a string.
- Write a Python program to implement a function that transforms a string so that only the first letter of each word is uppercase.
- Write a Python program to use regular expressions to identify word boundaries and apply capitalization accordingly.
Go to:
Previous Python Exercise: Replace a word with hash characters in a string.
Next Python Exercise: Extract the name from an Email address.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.