|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 2015-10-27 14:30 编辑
函数:- capwords(s, sep=None)
- capwords(s [,sep]) -> string
-
- Split the argument into words using split, capitalize each
- word using capitalize, and join the capitalized words using
- join. If the optional second argument sep is absent or None,
- runs of whitespace characters are replaced by a single space
- and leading and trailing whitespace are removed, otherwise
- sep is used to split and join the words.
复制代码
原型:
- def capwords(s, sep=None):
- return (sep or ' ').join(x.capitalize() for x in s.split(sep))
复制代码
代码:
- >>> import string
- >>> s = 'i love fisc.com'
- >>> print(string.capwords(s))
- I Love Fisc.com
- >>> print(string.capwords(s,sep='.'))
- I love fisc.Com
- >>>
复制代码
|
|