Python Dictionary 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)