- 简介
- Python strip()方法
于2022年4月29日开始整理,整理所以接触到的好用的python函数,一用来自己记录方便查看,二用来分享。
Python strip()方法
移除开头结尾指定的字符,中间不清理。
#!/usr/bin/python # -*- coding: UTF-8 -*- str1 = "00000003210Runoob01230000000"; print str1.strip( '0' ); # 去除首尾字符 0 str2 = " Runoob "; # 去除首尾空格 print str2.strip(); str3 = "123abcrunoob321" print (str3.strip( '12' )) # 字符序列为 12
输出结果:
P.S. 只要头尾包含有指定字符序列中的字符就删除,没有顺序关系。



