b = [0, 5, 2]
value = max(b) # 最大值
idx = b.index(value) # 最大值索引
print(value, idx)
输出:5 1
python获取列表list中最大的值,及其对应的索引
于 2022-03-07 17:20:46 首次发布

b = [0, 5, 2]
value = max(b) # 最大值
idx = b.index(value) # 最大值索引
print(value, idx)
输出:5 1