在Python中使用 enumerate ().
这里有一个例子,用 Python 中的 `enumerate()`函数来代一个果实列表,然后印出每个项目的索引. ``python fruits = ['apple', 'banana', 'ananas', 'grapes'] for index, fruit in enumerate(果实): print(f'index = {index}, fruit = {fruit}') ``` 这将产生以下输出: ``` index = 0, fruit = apple index = 1, fruit = banana index = 2, fruit = pineapple index = 3, fruit = grapes ``