Python中strip用法

str.strip([chars]);
移除字符串头尾指定的字符序列 ,chars -- 移除字符串头尾指定的字符序列,如果chars参数没有指定,则默认是去掉空格
str = "00000003210Runoob01230000000";
print(str.strip('0'));  # 去除首尾字符 0
str2 = "   Runoob      ";  # 去除首尾空格
print(str2.strip());


打印结果:


FR:海涛高软
QQ技术交流群:386476712 

猜你喜欢

转载自blog.csdn.net/qq_15267341/article/details/88544992