python大小写转换

作者: Bioconductor | 来源:发表于2016-09-28 23:11 被阅读406次

基于我的学习总结,这次分享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!

相关文章

网友评论

    本文标题:python大小写转换

    本文链接:https://www.haomeiwen.com/subject/uajkyttx.html