pyhon删除空白符

strip():可以删除字符串两端的空白符;
rstrip():可以删除字符串右侧的空白符;
lstrip():可以删除字符串左侧的空白符;

举个例子:

a = '   我爱python      '
b = a.strip()
print(b)

结果:

我爱python

猜你喜欢

转载自blog.csdn.net/weixin_42935779/article/details/102734399