开始使用免费开始使用

列表子集

现在,您已经用两个列表(ingredientsquantities)搭好了配方缩放器,接下来想快速预览购物清单。您需要从列表中访问特定元素,展示前几个食材及其用量,并检查列表中的最后一项是什么。

本练习是课程的一部分

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)
编辑并运行代码