通过循环获取列表的索引操作:
主要使用:enumerate
product_list = [['Iphone7',5800],
['Coffee',30],
['疙瘩汤',10],
['Python Book',99],
['Bike',199],
['ViVo X9',2499], ] for index,product in enumerate (product_list):
print(index,product)
运行结果
/anaconda3/envs/python36-oldboy/bin/python /Users/zhouyuqiang/Documents/面向对象/day22/test.py
0 ['Iphone7', 5800]
1 ['Coffee', 30]
2 ['疙瘩汤', 10]
3 ['Python Book', 99]
4 ['Bike', 199]
5 ['ViVo X9', 2499]
Process finished with exit code 0