![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements