Python 字符串大小写

Python 字符串大小写


作用: 改变字符串大小写,返回一个 新字符串。

方法 描述
s.capitalize()

将s[0]改为大写,其余小写 

s.lower() 让s的所有字母小写
s.upper() 让s的所有字母大写
s.swapcase() 将小写字母改为大写,并将大写字母改为小写

s.title()

让s的大小写符合标题的要求

示例:

s='go for it! Just do it!'
print('1:'+s.capitalize())
print('2:'+s.lower())
print('3:'+s.upper())
print('4:'+s.swapcase())
print('5:'+s.title())

结果:

原字符串:go for it! Just do it!
1:Go for it! just do it!
2:go for it! just do it!
3:GO FOR IT! JUST DO IT!
4:GO FOR IT! jUST DO IT!
5:Go For It! Just Do It!


座右铭: 走过一些弯路,也好过原地踏步

原创文章 20 获赞 22 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44687034/article/details/103604891