English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In Python, the capitalize() method converts the first character of a string to uppercase and converts all other characters (if any) to lowercase.
The syntax of capitalize():
string.capitalize()
capitalize() function without any parameters.
The capitalize() function returns a string with the first letter capitalized and all other characters lowercase. It does not modify the original string.
string = "pt.oldtoolbag.com" capitalized_string = string.capitalize() print('Old string: ', string) print('Capitalized string:', capitalized_string)
When running the program, the output is:
Old string: pt.oldtoolbag.com Capitalized string: pt.oldtoolbag.com
string = "+ is an operator." new_string = string.capitalize() print('Original string:', string) print('New string:', new_string)
When running the program, the output is:
Original string: + is an operator. New string: + is an operator.