Python - အဘိဓာန်အရာများကို ဖယ်ရှားပါ ။
ပစ္စည်းများကို ဖယ်ရှားခြင်း။
အဘိဓာန်မှ အရာများကို ဖယ်ရှားရန် နည်းလမ်းများစွာ ရှိပါသည်။
ဥပမာ
နည်းလမ်း သည် 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)