我试图检查列表中的任何项目是否以某个字符串开头。我怎样才能用 for 循环做到这一点? IE:
anyStartsWith = False
for item in myList:
if item.startsWith('qwerty'):
anyStartsWith = True
Use any() http://docs.python.org/library/functions.html#any:
any(item.startswith('qwerty') for item in myList)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)