Python string | capwords() method
In Python, string capwords() method is used to capitalize all the words in the string using split() method.
Syntax: string.capwords(string, sep=None)
Return Value: Returns a formatted string after above operations.
Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. If the optional second argument sep is absent or None, runs of whitespace characters are replaced by a single space and leading and trailing whitespace are removed, otherwise sep is used to split and join the words.
Code #1: If sep parameter is left None.
Python Is One Of The Best Programming Languages.
Code #2: When sep is not None.
When sep = "g" Python is one of the best progRamming langUagEs. When sep = "o" PythoN is oNe oF the best proGramming languages.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course