Home >>Python Dictionary Methods >Python Dictionary fromkeys() Method
Python Dictionary fromkeys() Method in python dictionary generate a new dictionary with the specified keys and the specified value.
Syntax:dict.fromkeys(keys, value)
Parameter | Description |
---|---|
keys | It is Required. An iterable specifying the keys to be transformed into the new dictionary |
value | It is Optional. The value need to be assigned for all keys |
a = ('num1', 'num2', 'num3')
b = 5
newdict = dict.fromkeys(a, b)
print(newdict)
ax = ('AB', 'BC', 'CD')
bx = 15
newdict1 = dict.fromkeys(ax, bx)
print(newdict1)