索引数列中某一个位置的值,以及索引数列中某一个特定值的位置

test_scores = [100, 97, 76, 84, 93, 98, 86, 92, 76, 88, 95, 90, 95, 93]
print(test_scores[14])
# 报错:IndexError: list index out of range
# (索引错误:超出列表范围)
print(test_scores[1])
#位置是1的值,返回97,这是给定数列中的位置,寻找对应的值

#如果知道值,寻找数列中的位置,如76
print(test_scores.index(76))
#那么会返回第一个符合条件的值的位置,这里是2

原文地址:https://www.cnblogs.com/mingzhuqi/p/13234584.html