Python字符串转大小写问题

str.lower() 字符串全小写。str.upper() 字符串全大写。

>>> str = 'my world, MY PYTHON'
>>> str.lower()
'my world, my python'
>>> str.upper()
'MY WORLD, MY PYTHON'

如何才能使字符串每个单词首字母都大写? 使 str = 'My World, My Python'

阅读 6k
2 个回答

参考文章:Python字符串操作相关问题

字符串大小写转换

str.lower() 字符串全小写。
str.upper() 字符串全大写。
str.capitalize() 字符串首字母大写。
str.title() 字符串每个单词首字母都大写。

>>> str = 'my world, MY PYTHON'
>>> str.lower()
'my world, my python'
>>> str.upper()
'MY WORLD, MY PYTHON'
>>> str.capitalize()
'My world, my python'
>>> str.title()
'My World, My Python'
str.title()
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题