Items method
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.
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
No comments:
Post a Comment