Function Details: get

Description


Returns the value for key if key is in the dictionary, else default.


Extended Description


The get() method returns the value for a given key in the dictionary. If the key is not found, it returns the default value, which is None if not specified. This method provides a safe way to retrieve values from a dictionary without raising a KeyError for non-existent keys.


Function Signature


dict.get(key: Any, default: Any = None) -> Any

Module: dict

Class: dictionary

Parameters



Parameter List


  • key: Any
  • default: Any

Return


Returns the value associated with the key if found, otherwise returns the default value.


Return Type


Any

Output

Explanation

This example shows basic usage of get() with existing and non-existing keys.