Python: Capitalize first and last letters of each word of a given string
Capitalize first and last letters of words.
Write a Python program to capitalize the first and last letters of each word in a given string.
Visual Presentation:
Sample Solution-1:
Python Code:
Sample Output:
PythoN ExerciseS PracticE SolutioN W3ResourcE
Flowchart:

Sample Solution-2:
Capitalizes the first letter of a string.
- Use list slicing and str.upper() to capitalize the first letter of the string.
- Use str.join() to combine the capitalized first letter with the rest of the characters.
- Omit the lower_rest parameter to keep the rest of the string intact, or set it to True to convert to lowercase.
Python Code:
Sample Output:
JavaScript Python
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to capitalize the first and last letters of each word in a sentence using split and join methods.
- Write a Python program to iterate over words in a string and transform each by capitalizing the first and last characters.
- Write a Python program to use list comprehension to modify each word so that its first and last letters are in uppercase.
- Write a Python program to implement this transformation using slicing and conditional expressions for words of varying lengths.
Go to:
Previous: Write a Python program to find the maximum occuring character in a given string.
Next: Write a Python program to remove duplicate characters of a given string.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.