python 字符串大小写转换

1.将字符串所有字符转为大写

upper()

str="StopPed by uSer"
print(str.upper())
#结果为 STOPPED BY USER

2.将字符串所有字符转为小写

lower()

str="StopPed by uSer"
print(str.lower())
#结果为 stopped by user

3.将字符串第一个字母转为大写,其余转成小写

capitalize()

str="stopPed by uSer"
print(str.capitalize())
#结果为 Stopped by user

4.将字符串每个单词的首字母转为大写,其余为小写

title()

str="StopPed by uSer"
print(str.title())
#结果为 Stopped By User

相关内容
istitle() 判断字符串是否是每个单词的首字母转为大写,其余为小写的形式

str="StopPed by uSer"
print(str.istitle())
#结果为 False
str="Stopped By User"
print(str.istitle())
#结果为True

你可能感兴趣的:(python 字符串大小写转换)