Home >Backend Development >Python Tutorial >How to use the python items() method

How to use the python items() method

藏色散人
藏色散人Original
2020-02-06 13:53:577133browse

How to use the python items() method

How to use the python items() method?

Python Dictionary (Dictionary) items() method

Python Dictionary (Dictionary) items() function returns a traversable (key, value) in a list Array of tuples.

Recommended: "Python Tutorial"

Grammar

##items() method syntax:

dict.items()

Parameter

NA.

Return value

Returns a traversable array of (key, value) tuples.

The following example shows how to use the items() function:

Example (Python 2.0)

#!/usr/bin/python
# coding=utf-8
 
dict = {'Google': 'www.google.com', 'Runoob': 'www.php.cn', 'taobao': 'www.taobao.com'}
 
print "字典值 : %s" %  dict.items()
 
# 遍历字典列表
for key,values in  dict.items():
    print key,values

The output result of the above example is:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.php.cn')]
Google www.google.com
taobao www.taobao.com  
php www.php.cn

The above is the detailed content of How to use the python items() method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to download pythonNext article:How to download python