Home »
Python
Python Dictionary items() Method with Example
Python Dictionary items() Method: Here, we are going to learn how to get the items of the dictionary as a view object?
Submitted by IncludeHelp, on November 25, 2019
Dictionary items() Method
items() method is used to get the all items as a view object, the view object represents the key-value pair of the dictionary.
Syntax:
dictionary_name.items()
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of this method is <class 'dict_items'>, it returns the items of the dictionary as view object.
Example:
# Python Dictionary items() Method with Example
# dictionary declaration
student = {
"roll_no": 101,
"name": "Shivang",
"course": "B.Tech",
"perc" : 98.5
}
# printing dictionary
print("data of student dictionary...")
print(student)
# printing items
print("items of student dictionary...")
print(student.items())
# printing return type of student.items() Method
print("return type is: ", type(student.items()))
Output
data of student dictionary...
{'name': 'Shivang', 'perc': 98.5, 'roll_no': 101, 'course': 'B.Tech'}
items of student dictionary...
dict_items([('name', 'Shivang'), ('perc', 98.5), ('roll_no', 101), ('course', 'B.Tech')])
return type is: <class 'dict_items'>
TOP Interview Coding Problems/Challenges