考虑一个基本的元组
,它与内置方法str.startswith()
一起使用:
>>> t = 'x','y','z'
>>> s = 'x marks the spot'
>>> s.startswith( t )
True
当使用带有 str.strip()
的元组时,需要使用循环:
>>> for i in t: s.strip(i)
...
' marks the spot'
'x marks the spot'
'x marks the spot'
这似乎有些浪费;在使用 str.strip()
与元组项时,是否有更有效的方法?s.strip(t)
看起来很合理,然而不行。