python大小写转换

来源:互联网 发布:改键软件 编辑:程序博客网 时间:2024/05/13 23:26

基于我的学习总结,这次分享python字符大小写的转换,讲述4种方法

大写

把所有字符中的小写字母转换成大写字母

>>> str = "hELLO world!">>> print (str.upper())HELLO WORLD!

小写

把所有字符中的大写字母转换成小写字母

>>> str = "hELLO world!">>> print (str.lower())hello world!

第一个字母转为大写

把第一个字母转化为大写字母,其余小写

>>> str = "hELLO world!">>> print (str.capitalize())Hello world!

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

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

>>> str = "hELLO world!">>> print (str.title())Hello World!
0 0