The capitalize() function in python helps to convert the first character of the string to uppercase and all the remaining characters to lowercase if any. The converted string is returned as output without affecting the original string.
The capitalize() function doesn't take any parameter. If the first character of the string is already a capital letter it will return the original string.
The return value of this method is a copy of the original string by changing its first character into uppercase all remaining as lowercase. If the string is empty, it will return an empty string as output. Again if we use a numeric string like "12", it will return an error.
|If string||string with the first character in uppercase|
string = "hiii How are You." capitalized = string.capitalize() print('Old String is: ', string) print('Capitalized String is:', capitalized)
Old String is: hiii How are You. Capitalized String is: Hiii how are you.
string = "* is a multiple operator." updated_string = string.capitalize() print('Old String is:', string) print('New String is:', updated_string)
Old String is: * is a
multipleoperator. New String is: * is a