How to use the python items() method

藏色散人
Release: 2020-02-06 13:53:57
Original
6907 people have browsed it

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()
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!