Function Details: fromkeys

Description


Creates a new dictionary with keys from iterable and values set to value.


Extended Description


The fromkeys() method is a class method that creates a new dictionary. The first parameter is an iterable defining the keys of the new dictionary. The second optional parameter specifies the value for all keys, which defaults to None if not provided. This method is particularly useful when you want to create a dictionary with preset keys and a default value.


Function Signature


dict.fromkeys(iterable: Iterable, value: Any = None) -> dict

Module: dict

Class: dictionary

Parameters



Parameter List


  • iterable: Iterable
  • value: Any

Return


Returns a new dictionary with keys from the iterable and values set to the specified value.


Return Type


dictionary

Output

Explanation

This example creates a dictionary with keys from a list and sets all values to 0.