Capitalize the First Letter of Each Word in Python Using capitalize()

Python Program to Capitalize the First Letter of Each Word in Python Using capitalize() Function

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Run
Run Code
#Capitalize the First Letter of Each Word in Python Using capitalize()
s = "python is the most popular programming language"
print("Original string: " +s)
print("After capitalizing the first letter:")
#capitalize() method converts each word's first letter to uppercase, giving the desired output.
result = ' '.join(elem.capitalize() for elem in s.split())
print(result)
#Capitalize the First Letter of Each Word in Python Using capitalize() s = "python is the most popular programming language" print("Original string: " +s) print("After capitalizing the first letter:") #capitalize() method converts each word's first letter to uppercase, giving the desired output. result = ' '.join(elem.capitalize() for elem in s.split()) print(result)
#Capitalize the First Letter of Each Word in Python Using capitalize()

s = "python is the most popular programming language"
print("Original string: " +s) 
print("After capitalizing the first letter:")

#capitalize() method converts each word's first letter to uppercase, giving the desired output.
result = ' '.join(elem.capitalize() for elem in s.split())
print(result)

Output:

Original string: python is the most popular programming language
After capitalizing the first letter: Python Is The Most Popular Programming Language

About The Author

Leave a Reply