Python学习_lstrip、rstrip、strip的区别与使用

1.lstrip:去掉左边空格
2.rstrip:去掉右边空格
3.strip:去掉左、右两边空格
案例:

name="    东  宫    "
#输入原字符串来与新字符串做对比
print(name) 
print(name.lstrip())
print(name.rstrip())
print(name.strip())

运行结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/zyl2726411159/article/details/87906753