代码如下:
#encoding=utf-8 print '中国' #字符串大小写转化 str ='aBc中国' ustr =u'aBc中国' print str.upper() print str.lower() print str.capitalize() #第一个大写其余小写 print ustr.upper() print ustr.lower() print ustr.capitalize() #判断是否是第一个大写其余小写 不适用于空字符串和非字母字符串 def isCapitalize(s): return s == s.capitalize() print isCapitalize(str) print isCapitalize(ustr)
运行结果:
中国
ABC中国
abc中国
Abc中国
ABC中国
abc中国
Abc中国
False
False