列表子集
现在,您已经用两个列表(ingredients 和 quantities)搭好了配方缩放器,接下来想快速预览购物清单。您需要从列表中访问特定元素,展示前几个食材及其用量,并检查列表中的最后一项是什么。
本练习是课程的一部分
Python for Developers 入门
交互式实操练习
通过完成这段示例代码来试试这个练习。
ingredients = ["fusilli", "tomatoes", "garlic", "basil", "olive oil", "salt"]
quantities = [500, 400, 15, 20, 30, 10]
# Get the second ingredient for your preview
second_ingredient = ____
print(second_ingredient)