Method Name:
keys
Method Signature:
keys()
Method Overview:
- The keys() method returns all the keys of a Python dictionary instance as a dict_keys.
- The returned dict_keys changes its view as the keys of the original dictionary instance changes.
Parameters:
None
Return Value:
The keys of the dictionary as an instance of dict_keys class.
Example:
# Example Python program that retrieves airport_codes = airports.keys(); print("Dictionary view:"); # Iterate the view and print the airport codes # Add more airport codes # Print the view after changes to the original dictionary |
Output:
Dictionary view: ATL BWI DFW JFK LAX ORD SFO New dictionary view: ATL BWI DFW JFK LAX ORD SFO EWR DEN |