strip
我们常常使用它去掉两边空白字符
如str01.strip(" ")
, 这样使用没有什么问题
但是像我,对它的理解就存在偏差
之前的理解是a.strip("tom")
去掉a
字符串 两边的 tom
,开头结尾严格匹配。
看下面的例子,可能就不符合我们的预期。
# python3.7.6 后面的版本会不会变不知道
In [1]: a = "tomm xxx mmm"
In [2]: a.strip("tom")
Out[2]: ' xxx '
In [3]: a = "tot a totma"
In [4]: a.strip("toma")
In [4]: Out: ' a '
从现象来看,a.strip("toma")
"toma"
,可以转化成一个集合,匹配开头结尾的时候,以第一个不在集合内的字符结束