पायथन डिक्शनरी फ्रॉमकीज़ () विधि
उदाहरण
3 कुंजियों के साथ एक डिक्शनरी बनाएं, सभी का मान 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)