温馨提示×

python让所有单词首字母大写

小亿
111
2023-11-14 01:46:16
栏目: 编程语言

要将一个字符串中的所有单词的首字母大写,可以使用字符串的 title() 方法。这个方法返回一个新的字符串,其中所有单词的首字母都大写。

下面是一个例子:

string = "hello world"
new_string = string.title()
print(new_string)

输出:

Hello World

在上面的例子中,字符串 "hello world" 中的每个单词的首字母都被转换成了大写。

0