第一章:文本-文本常量和模板-函数

1.1 string:文本常量和模板
1.1.1 函数
函数capwords()会把一个字符串中的所有单词首字母大写。

import string
s = "The quick brown fox jumped over the lazy dog."
print(s)
print(string.capwords(s))

运行结果:
在这里插入图片描述
这个代码的结果等同于先调用split(),把结果列表中的单词首字母大写,然后调用 join()来合并结果。

猜你喜欢

转载自blog.csdn.net/weixin_43193719/article/details/86652204