طريقة الحصول على قاموس بايثون
مثال
احصل على قيمة عنصر "النموذج":
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("model")
print(x)
التعريف والاستخدام
تقوم get()
الطريقة بإرجاع قيمة العنصر بالمفتاح المحدد.
بناء الجملة
dictionary.get(keyname, value)
قيمه المعامل
Parameter | Description |
---|---|
keyname | Required. The keyname of the item you want to return the value from |
value | Optional. A value to return if the specified key does not exist. Default value None |
مزيد من الأمثلة
مثال
حاول إرجاع قيمة عنصر غير موجود:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("price", 15000)
print(x)