![]() |
VOOZH | about |
capwords() method in Python is a part of the string module and is used to capitalize the first letter of every word in a given string while converting all other letters to lowercase. To use capwords(), the string module must be imported as it is not a built-in string method.
Learn Python With Geeksforgeeks!
Explanation:
string.capwords() method processes the string 's' by splitting it into words, capitalizing the first letter of each word and joining them back together.Table of Content
string.capwords(string, sep=None)
When working with sentences, ensuring consistent capitalization can significantly enhance readability. This method is especially useful in titles and headings.
Learn Python With Geeksforgeeks!
s' contains all lowercase words.capwords() method capitalizes the first letter of each word and lowers the rest, resulting in proper formatting.When strings use specific separators like commas or hyphens instead of spaces, the sep parameter can be used for precise formatting.
Learn-Python-With-Geeksforgeeks!
sep parameter specifies "-" as the delimiter.This method is ideal for normalizing text where some words are already capitalized or contain uppercase letters.
Learn Python With Geeksforgeeks!
capwords() method converts all letters to lowercase first, then capitalizes the first letter of each word.