Python中的字符串大写()
在Python中, capitalize()方法返回原始字符串的副本,并将字符串的第一个字符转换为大写(大写)字母,同时将字符串中的所有其他字符转换为小写字母。
句法:
string_name.capitalize()
string_name: It is the name of string of
whose first character we want
to capitalize.
参数: capitalize()函数不带任何参数。
返回值: capitalize()函数返回第一个字符大写的字符串。
下面是说明 capitalize()函数的Python程序:
Python
# Python program to demonstrate the
# use of capitalize() function
# capitalize() first letter of string
# and make other letters lowercase
name = "geeks FOR geeks"
print(name.capitalize())
# demonstration of individual words
# capitalization to generate camel case
name1 = "geeks"
name2 = "for"
name3 = "geeks"
print(name1.capitalize() + name2.capitalize()
+ name3.capitalize())
输出:
Geeks for geeks
GeeksForGeeks