python大小写转换

基于我的学习总结,这次分享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!
    原文作者:Bioconductor
    原文地址: https://www.jianshu.com/p/dbe6a5e36fb8
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞