python " />

扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python让所有单词首字母大写

扬州沐宇科技
2023-11-14 01:46:16
python

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

下面是一个例子:

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

输出:

Hello World

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

扫码添加客服微信