Python String capitalize() Method, it is an in-built method in Python and it is used to return capitalized string.
Python String capitalize方法用法及代码示例 Python 的str.capitalize(~)方法将字符串的第一个字符转换为标题大写,并将所有其他字符转换为小写。这意味着二合字母字符只会将其第一个字母大写。 参数 无参数。 返回值 一个新字符串,其中字符串的第一个字符转换为标题大小写。 例子 要将"hello there. How aRe you...
ThePython String capitalize()method is used to capitalize the current string. It simply returns a string with the very first letter capitalized, that is in upper case and the remaining characters of that string are converted to lower case letters. If the first letter of the input string is a...
New value:Javatpoint Python 字符串 Capitalize() 方法示例 2 如果第一个字符已经存在大写怎么办。 # Pythoncapitalize() function example# Variable declarationstr ="Javatpoint"# Calling functionstr2 = str.capitalize()# Displaying resultprint("Old value:", str) print("New value:", str2) 输出: O...
Python capitalize() method capitalizes a string i.e. upper case the first letter in the given string and lower case all other characters, if any.
Capitalize a String Using Built-in Capitalize MethodFinally, Python comes equipped with the capitalize() method right out of the box. Unfortunately, it doesn’t quite adhere to our requirements because it does a bit more than just capitalize the first character of a string. In addition, it ...
This method will also capitalize the first letter of every word in the string while all remaining characters are lower-case. The complete example code is given below: importre string="learn python"string=re.sub("([a-zA-Z])",lambdax:x.groups()[0].upper(),string,1)print("The capitaliz...
capitalized_string = ' '.join(elem.capitalize() for elem in string.split()) # Example 6: Capitalize the first letter of each word capitalized_string = [word.title() for word in string] 2. Usage of String capitalize() Method The string.capitalize() method in Python that takes a string...
Example 1: Python capitalize() sentence ="python is AWesome." # capitalize the first charactercapitalized_string = sentence.capitalize() print(capitalized_string) Run Code Output Python is awesome. In the above example, we have used thecapitalize()method to convert the first character of thesente...
Capitalizes first letter of each word in a string using loop, split() method# python program to capitalizes the # first letter of each word in a string # function def capitalize(text): return ' '.join(word[0].upper() + word[1:] for word in text.split()) # main code str1 = ...