品易云推流 关闭
文章详情页
文章 > Python基础教程 > python字符串中有哪些方法

python字符串中有哪些方法

Python字符串

头像

小妮浅浅

2021-06-09 19:17:365344浏览 · 0收藏 · 0评论

字符串方法

1.capitalize() :将字符串的第一个字符转换为大写字母

2.title():将所有单词的第一个字符转换为大写字母

3.upper():将字符串的所有字符转化为大写字母

4.lower():将字符串的所有字符转化为小写字母

5.swapcase() :将字符串的所有字符大小写互换

实例

>>> string = 'while There is life There is hope.'
 
>>> string.capitalize()
# 'While there is life there is hope.'
>>> string.title()
# 'While There Is Life There Is Hope.'
>>> string.upper()
# 'WHILE THERE IS LIFE THERE IS HOPE.'
>>> string.lower()
# 'while there is life there is hope.'
>>> string.swapcase()
# 'WHILE tHERE IS LIFE tHERE IS HOPE.'

以上就是python字符串方法的介绍,希望对大家有所帮助。更多Python学习指路:python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图