upper()将字符串所有字符改变为大写;lower()将字符串所有字符改变为小写;capitalize()将字符串第一个字符大写,其余小写;title()将字符串每个单词的第一个字母大写,其余小写。
>>> print 'one tWo thrEe'.capitalize()
One two three
>>> print 'one tWo thrEe'.title()
One Two Three
自定义的iscapitalized()函数
import string
notrans = string.maketrans('', '') #identity''translation''
def containsAny(str, strset):
return len(strset) != len(strset.translate(notrans, str))
def iscapitalized(s):
return s == s.capitalize() and containsAny(s, string.letters)