Definition
The fromkeys() method returns a dictionary with the specified keys and the specified value.
Syntax
dict.fromkeys(keys, value)
Parameters
Parameter | Description |
---|---|
keys | Required. An iterable specifying the keys of the new dictionary |
value | Optional. The value for all keys. Default value is None |
Examples:
person = ('name', 'age', 'country')
name = "Mark"
myDict = dict.fromkeys(person, name)
print(myDict)
# another example
person = ('name', 'age', 'country')
name = "Mark"
myDict = dict.fromkeys(person)
print(myDict)