string.capwords() 将每个单词首字母大写

时间:2016-06-11 15:51:52   收藏:0   阅读:104

string.capwords() 将每个单词首字母大写

代码:

技术分享
import string

s = ‘ The quick brown fox jumped over the lazy dog. ‘

print s
print string.capwords(s)
技术分享

结果:

 

The quick brown fox jumped over the lazy dog.
The Quick Brown Fox Jumped Over The Lazy Dog.
请按任意键继续. . .

 

string模块中的capwords()函数,除了可以将每个单词首字母大写以外,它还能够去除两端的空格,再将连续的空格用一个空格代替。

原文:http://www.cnblogs.com/yymn/p/5575380.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!