时间:2021-07-01 10:21:17 帮助过:14人阅读
代码如下:
s = 'hEllo pYthon'
print s.upper()
print s.lower()
print s.capitalize()
print s.title()
代码如下:
print 'A'.isupper() #True
print 'A'.islower() #False
print 'Python Is So Good'.istitle() #True
#print 'Dont do that!'.iscapitalize() #错误,不存在iscapitalize()方法
代码如下:
import string
notrans = string.maketrans('', '')
def containsAny(str, strset):
return len(strset) != len(strset.translate(notrans, str))
def iscapitalized(s):
return s == s.capitalize( ) and containsAny(s, string.letters)
#return s == s.capitalize( ) and len(s) > 0 #如果s为数字组成的字符串,这个方法将行不通调用一下试试:
print iscapitalized('123')
print iscapitalized('')
print iscapitalized('Evergreen is zcr1985')