Python သည် Dictionary တစ်ခုမှ အရာများကို ဖယ်ရှားခြင်း
အဘိဓာန်မှ အကြောင်းအရာများကို ဖယ်ရှားခြင်း။
အဘိဓာန်မှ အရာများကို ဖယ်ရှားရန် နည်းလမ်းများစွာ ရှိပါသည်။
ဥပမာ
နည်းလမ်း သည် pop()
သတ်မှတ်ထားသော သော့အမည်ဖြင့် အကြောင်းအရာကို ဖယ်ရှားသည်-
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.pop("model")
print(thisdict)
ဥပမာ
နည်းလမ်းသည် နောက်ဆုံးထည့်သွင်းထားသော အရာအား ဖယ်ရှားသည် ( popitem()
3.7 မတိုင်မီ ဗားရှင်းများတွင်၊ အစား ကျပန်းအရာတစ်ခုကို ဖယ်ရှားသည်)
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.popitem()
print(thisdict)
ဥပမာ
သော့ချက်စကားလုံး သည် del
သတ်မှတ်ထားသောသော့အမည်ဖြင့် အကြောင်းအရာကို ဖယ်ရှားသည်-
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
del thisdict["model"]
print(thisdict)
ဥပမာ
သော့ချက်စကားလုံး သည် del
အဘိဓာန်ကိုလည်း လုံးလုံးလျားလျား ဖျက်နိုင်သည်-
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
del thisdict
print(thisdict) #this will cause an error because "thisdict"
no longer exists.
ဥပမာ
သော့ချက်စကားလုံးသည် အဘိဓာန် ကို clear()
လွတ်သွားသည်-
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.clear()
print(thisdict)