
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to capitalize each word's first letter
Suppose we have a sentence with English lowercase letters. We have to convert first letter of each word into uppercase.
So, if the input is like s = "i love my country", then the output will be "I Love My Country"
To solve this, we will follow these steps −
- words := list of words from s
- ret := a new blank list
- for each i in words, do
- capitalize first letter of i using capitalize() function and insert it into ret
- join each words present in ret separated by blank space and return
Example
Let us see the following implementation to get better understanding
def solve(s): words = s.split(' ') ret = [] for i in words: ret.append(i.capitalize()) return ' '.join(ret) s = "i love my country" print(solve(s))
Input
"i love my country"
Output
I Love My Country
- Related Articles
- How to capitalize the first letter of each word in a string using JavaScript?
- Pandas dataframe capitalize first letter of a column
- Capitalize last letter and Lowercase first letter of a word in Java
- Capitalize first letter of a column in Pandas dataframe
- Golang program to capitalize first character of each word in a string
- Capitalize only the first letter after colon with regex and JavaScript?
- Java Program to Capitalize the first character of each word in a String
- Java Program to Print first letter of each word using regex
- Golang program to print first letter of each word using regex
- C++ Program to Print first letter of each word using regex
- MySQL query to update all records to capitalize only the first letter and set all others in lowercase
- Capitalizing first letter of each word JavaScript
- How can we capitalize only first letter of a string with the help of MySQL function/s?
- Python Program to Capitalize repeated characters in a string
- Write a Java program to capitalize each word in the string?

Advertisements