python字符串中有哪些方法

458次阅读
没有评论

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.'
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-04-26发表,共计484字。
新手QQ群:570568346,欢迎进群讨论 Python51学习