温馨提示×

python中的title函数怎么使用

小亿
133
2023-11-13 22:19:26
栏目: 编程语言

在Python中,title函数用于将字符串的每个单词的首字母转为大写,而其余字母转为小写。使用方法如下:

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

输出结果为:

Hello World

在上述例子中,我们定义了一个字符串变量string,其值为"hello world"。然后,我们调用title函数string.title(),将字符串的每个单词的首字母转为大写字母,而其余字母转为小写字母。最后,我们打印输出结果。

0