Python Dictionary items() MethodPython item() method returns a new view of the dictionary. This view is collection of key value tuples. This method does not take any parameter and returns empty view if the dictionary is empty. The examples and syntax are given below. SignatureParametersNo parameter ReturnIt returns a dictionary's view. Let's see some examples of items() method to understand it's functionality. Python Dictionary items() Method Example 1This is a simple example which returns all the items present in the dictionary. Output: dict_items([('name', 'rohan'), ('course', 'B.Tech'), ('email', '[email protected]')]) Python Dictionary items() Method Example 2If the dictionary is already empty, this method does not raise any error. See the example below. Output: dict_items([]) Python Dictionary items() Method Example 3Apart from items() method, we can also use other customized approaches to fetch dictionary elements. See an example below. Output: ( name : rohan), ( course : B.Tech), ( email : [email protected]), dict_items([('name', 'rohan'), ('course', 'B.Tech'), ('email', '[email protected]')])
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