Python Sözlüğü fromkeys() Yöntemi
Örnek
Hepsi 0 değerine sahip 3 tuşlu bir sözlük oluşturun:
x = ('key1', 'key2', 'key3')
y = 0
thisdict = dict.fromkeys(x, y)
print(thisdict)
Tanım ve Kullanım
Yöntem fromkeys()
, belirtilen anahtarlara ve belirtilen değere sahip bir sözlük döndürür.
Sözdizimi
dict.fromkeys(keys, value)
Parametre Değerleri
Parameter | Description |
---|---|
keys | Required. An iterable specifying the keys of the new dictionary |
value | Optional. The value for all keys. Default value is None |
Daha fazla örnek
Örnek
Yukarıdakiyle aynı örnek, ancak değeri belirtmeden:
x = ('key1', 'key2', 'key3')
thisdict = dict.fromkeys(x)
print(thisdict)