我有一个字符串,我试图得到值“bad”的索引,由于某种原因它抛出了一个错误。你知道吗
>>> s = "This dinner is not that bad!"
>>> l = s.split()
>>> bad_index_value = l.index('bad')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: list.index(x): x not in list
Tags:
实际上,您的列表中没有
bad
它的bad!
。如果要查找bad
的索引,可以使用'!'
剥离元素:从技术上讲,
bad
不存在于您的输入This dinner is not that bad!
,它的bad!
相关问题 更多 >
编程相关推荐