知行编程网知行编程网  2022-09-15 11:00 知行编程网 隐藏边栏  1 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python字符串中有哪些方法的相关知识,包括python字符串查找,以及python字符串添加字符这些编程知识,希望对大家有参考作用。

python字符串中有哪些方法


字符串方法

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.'


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

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享