python 字符串大小写相关函数

改写:(都不会改变原字符串)

s = 'hEllo wOrld'
s
Out[3]: 'hEllo wOrld'
s.upper()#全部大写
Out[4]: 'HELLO WORLD'
s
Out[5]: 'hEllo wOrld'
s.lower()#全部小写
Out[6]: 'hello world'
s
Out[7]: 'hEllo wOrld'
s.capitalize()#首字母大写
Out[8]: 'Hello world'
s
Out[9]: 'hEllo wOrld'
s.title()#每个词首字母大写
Out[10]: 'Hello World'
s
Out[11]: 'hEllo wOrld'

#大变小小变大

s.swapcase()
Out[15]: 'HeLLO WoRLD'

 

判断:

s.isupper()
Out[12]: False
s.islower()
Out[13]: False
s.istitle()
Out[14]: False
原文地址:https://www.cnblogs.com/zywscq/p/10562565.html