Back to Browse

57.Capitalize First Letter of Each Word in Python | Beginner-Friendly Tutorial

27 views
Sep 23, 2025
8:46

In this video, we’ll learn how to capitalize the first letter of every word in a sentence using Python. We’ll go step by step, breaking down the logic so beginners can follow easily. 🔹 Key Line Explanation: capitalized = [word[0].upper() + word[1:] if word else "" for word in words] Here’s what it does: for word in words → Loops through each word in the sentence. word[0].upper() → Takes the first letter and converts it to uppercase. + word[1:] → Adds the rest of the word unchanged. if word else "" → Handles empty strings safely (in case of extra spaces). [ ... for word in words ] → Creates a new list of capitalized words. Finally, we use " ".join(capitalized) to rebuild the sentence. ✅ Example: Input: learn code easily with python Output: Learn Code Easily With Python 👉 This program is useful for text formatting, titles, and data cleaning.

Download

0 formats

No download links available.

57.Capitalize First Letter of Each Word in Python | Beginner-Friendly Tutorial | NatokHD