天天看点

python 大小写转换

大写:

    把所有字符转换为大写

str='hello woRld'
print(str.upper())      
str='hello woRld'
print(str.upper())      

HELLO WORLD

小写:

    把所有字符转换成小写

str='HELLO WOrld'
print(str.lower())      
str='HELLO WOrld'
print(str.lower())      

把第一个字母大写,其余小写:

str='hello world'
print(str.capitalize())      
str='hello world'
print(str.capitalize())      

每个单词的第一个字母大写

把每个单词的第一个字母转化为大写,其余小写

str='hello world'
print(str.title())      
str='hello world'
print(str.title())