Python Dictionary | Items method | Definition and usage


Python Dictionary | Items method | Definition and usage

Definition and usage

The item () method returns a visible object. The
 visual object contains the dictionary's key-value
 pairs, such as tuples in a list.

The visual object will reflect any changes made to
 the dictionary, see example below.


How to create python dictionary

Syntax

dictionary.items ()
Parameter value
No parameters

Python 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.

user_items = user_info.items()
print(user_items)

OutPut

 dict_items([('name', 'pramod'), ('age', 22)
, ('rollno', '17691a05b9'), ('class', 'B-Tech')])
#this is printing like tuple item inside a list

for key,value in user_info.items():
    print(f'key is {key} and values is {value}')

OutPut

key is name and values is pramod
key is age and values is 22key is rollno and  values is 17691a05b9
key is class and values is B-Tech

Python Dictionary | Items method | Definition and usage
python di

Python Dictionary | Items method | Definition and usage – w3school

Tags

python dictionary operations, create dictionary python, create python dictionary, python dictionary methods, python dictionary append ,
python dictionary keys ,
python nested dictionary,
python dictionary of dictionaries,
python dictionary add item ,
python create dictionary from list,
python list(),
python dictionary append,
python list of dictionaries ,
python dictionary keys ,
python nested dictionary,
python empty dictionary,how to create python dictionary, python dictionary add, python dictionary get, python dictionary methods,python dictionary append,python dictionary update,python dictionary iterate, python dictionary in dictionary, python dictionary example, python dictionary items, python dictionary functions, python dictionary create,python dictionary api, python dictionary from list, python dictionary example code,

Have any Question or Comment?

One comment on “Python Dictionary | Items method | Definition and usage

[…] Python Dictionary | Items method | Definition and usage […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories