当前位置:主页 > 软件编程 > Python代码 >

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

时间:2021-08-09 08:51:50 | 栏目:Python代码 | 点击:

1.字符串大小写转换

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)
HelloWorld
str3 = str1+str2
print(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 Beijing
Hello Beijing

总结

您可能感兴趣的文章:

相关文章