طريقة قاموس Python pop ()
مثال
إزالة "النموذج" من القاموس:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
car.pop("model")
print(car)
التعريف والاستخدام
الطريقة pop()
تزيل العنصر المحدد من القاموس.
قيمة العنصر الذي تمت إزالته هي قيمة الإرجاع pop()
للطريقة ، انظر المثال أدناه.
بناء الجملة
dictionary.pop(keyname, defaultvalue)
قيمه المعامل
Parameter | Description |
---|---|
keyname | Required. The keyname of the item you want to remove |
defaultvalue | Optional. A value to return if the specified key do not exist. If this parameter is not specified, and the no item with the specified key is found, an error is raised |
مزيد من الأمثلة
مثال
قيمة العنصر الذي تمت إزالته هي القيمة المرجعة لطريقة pop ():
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.pop("model")
print(x)