這個問題在這里已經有了答案: 訪問 Python 字典中的嵌套鍵值 2 個答案 昨天關門。
我目前正在 Udemy 上進行 100 天的代碼課程,并且已經獲得了此代碼。
menu = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
},
"cost": 1.5,
},
"latte": {
"ingredients": {
"water": 200,
"milk": 150,
"coffee": 24,
},
"cost": 2.5,
},
"cappuccino": {
"ingredients": {
"water": 250,
"milk": 100,
"coffee": 24,
},
"cost": 3.0,
}
}
我如何稱呼“成本”部分?
uj5u.com熱心網友回復:
您可以使用menu['<name of item you want to get cost for>']['cost'].
例如,print(menu['espresso']['cost'])應該輸出1.5.
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/451071.html
