版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
版权
Python专栏收录该内容
49 篇文章0 订阅
订阅专栏

python求列表中数字的最大值最小值及下标

a = [2,3,4,5,6,7] max_num = a[0] min_num = a[0] max_index = 0 min_index = 0 for i in range(len(a)): if a[i]>max_num: max_num = a[i] max_index = i else: min_num = a[i] min_index = i print(max_num,max_index,min_num,min_index)