码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-06-11 15:52:24      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

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()函数,除了可以将每个单词首字母大写以外,它还能够去除两端的空格,再将连续的空格用一个空格代替。

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!