【发布时间】:2015-10-02 07:45:26
【问题描述】:
考虑一个基本的tuple 与内置方法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) 似乎合乎逻辑,然而,没有。
【问题讨论】:
标签: python python-3.x split tuples strip