Python Dictionary keys() MethodPython keys() method is used to fetch all the keys from the dictionary. It returns a list of keys and an empty list if the dictionary is empty. This method does not take any parameter. Syntax of the method is given below. SignatureParametersNo parameter ReturnIt returns a list of keys. None if the dictionary is empty. Let's see some examples of keys() method to understand it's functionality. Python Dictionary keys() Method Example 1Let's first see a simple example to fetch keys from the dictionary. Output: dict_keys(['name', 'brand', 'price']) Python Dictionary keys() Method Example 2Output: product price is too high Python Dictionary keys() Method Example 3We can use this method into our python program. Here, we are using it into a program to check our inventory status. Output: We have sufficient inventory for the bananas
Next TopicPython Dictionary
|
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week