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'>






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.