Python Dictionary fromkeys() နည်းလမ်း
ဥပမာ
သော့ ၃ လုံးဖြင့် အဘိဓာန်တစ်ခုကို ဖန်တီးပါ၊ အားလုံးသည် တန်ဖိုး 0 ဖြစ်သည်-
x = ('key1', 'key2', 'key3')
y = 0
thisdict = dict.fromkeys(x, y)
print(thisdict)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
fromkeys()
နည်းလမ်းသည် သတ်မှတ်ထားသောသော့များနှင့် သတ်မှတ်ထားသောတန်ဖိုးဖြင့် အဘိဓာန်ကို ပြန်ပေးသည် ။
အထားအသို
dict.fromkeys(keys, value)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
keys | Required. An iterable specifying the keys of the new dictionary |
value | Optional. The value for all keys. Default value is None |
နောက်ထပ် ဥပမာများ
ဥပမာ
အထက်ဖော်ပြပါ ဥပမာနှင့် တူသော်လည်း တန်ဖိုးကို မသတ်မှတ်ဘဲ၊
x = ('key1', 'key2', 'key3')
thisdict = dict.fromkeys(x)
print(thisdict)