python中的lstrip、rstrip、strip

lstrip()移除左侧空白符

rstrip()移除右侧空白符

strip()移除两边的空白符

1 a = "    hello world"
2 a1 = a.lstrip()3 print(a1)

输出结果:

hello world
1 b = "hello world    "
2 b1 = b.rstrip()
3 print(b1)

输出结果:

hello world
1 c = "    hello world        "
2 c1 = c.strip()
3 print(c1)

输出结果:

hello world

使用方法如代码书写

原文地址:https://www.cnblogs.com/zhangzengqiang/p/7524889.html