Python Dictionary fromkeys() Method

Python Dictionary fromkeys() Method

  • Python Dictionary fromKeys() is an inbuilt function that creates a new dictionary from the given sequence of elements with a value provided by the user. 

  • The fromKeys method returns the dictionary with specified keys and values. 

  • The fromkeys() helps us achieve this very task with ease and using just a single method.

Syntax

  • dict.fromkeys(keys, value) 

Parameter Values

keys               

Required. An iterable specifying the keys of the new dictionary

value

Optional. The value for all keys. Default value is None

 

 

 

Comments