来自:http://blog.csdn.net/xxzhangx/article/details/52695089

大写

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

>>> str = "hELLO world!"
>>> print (str.upper())
HELLO WORLD!
 
 
  • 1
  • 2
  • 3
小写

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

>>> str = "hELLO world!"
>>> print (str.lower())
hello world!
 
 
  • 1
  • 2
  • 3
第一个字母转为大写

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

>>> str = "hELLO world!"
>>> print (str.capitalize())
Hello world!
 
 
  • 1
  • 2
  • 3
每个单词的第一个字母大写

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

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

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐