首页 > 编程 > Python > 正文

Python字符串大小写转换拼接删除空白

2019-11-25 11:41:30
字体:
来源:转载
供稿:网友

1.字符串大小写转换

  • string.title() #将字符串中所有单词的首字母以大写形式显示
  • string.upper() #将字符串中所有字母转化为大写字母
  • string.lower() #将字符串中所有字母转化为小写字母
str = "hello world!"print(str.title())Hello World!print(str.upper())HELLO WORLD!print(str.lower())hello world!

2.字符拼接

python中只用使用'+'便可以进行字符串拼接

str1 = 'Hello'str2 = 'World'print(str1+str2)HelloWorldstr3 = str1+str2print(str3)HelloWorld

3.删除空白

string.lstrip() #删除串首的空白string.rstrip() #删除串尾的空白string.strip() #删除左右量表的空白

strip的意思就是剥夺,所以lstrip()就是剥夺left_strip,剥除左边的数组即串首的空白

str = ' Hello Beijing 'print(str.lstrip())print(str.rstrip())print(str.strip())
Hello Beijing  Hello BeijingHello Beijing

总结

以上所述是小编给大家介绍的Python字符串大小写转换拼接删除空白,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表