操作 dictionaries
目前為止,你已經把食材及其克數加入了。
現在,你想用不同的方法存取字典的內容,確認字典如預期建立,並為之後的配方放大做準備。
本練習屬於課程
Python 入門(開發者向)
練習說明
- 使用一個方法從
recipe字典擷取所有鍵,並將結果指派給ingredient_names。 - 使用一個方法從
recipe字典擷取所有值,並將結果指派給quantities。 - 使用一個方法從
recipe字典擷取所有鍵值配對,並將結果指派給recipe_items。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get all ingredient names
ingredient_names = ____
# Get all quantities
quantities = ____
# Get all key-value pairs
recipe_items = ____
print("Ingredient names:", ingredient_names)
print("Quantities:", quantities)
print("Recipe items:", recipe_items)