x = ['some', 'fairly', 'long', 'string']
if "fairly" in x:
return index?
有没有简单的方法可以得到“公平”的指标?
最佳答案
为什么不在 try-except
block 中使用内置的 index
方法?
lst = ["fairly","blue","car"]
x = "fairly"
try:
print lst.index(x)
except ValueError:
print "{0} not in list".format(x)
关于python - 当我使用 "if string in list:"时是否可以在列表中获取索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13534476/