What is the python items function? How to use it?

乌拉乌拉~
Release: 2018-08-18 17:55:00
Original
25784 people have browsed it

In this article, let’s learn about the python items function in the python dictionary. What does the items function mean? What effect does this function have? Get the answer in the following article.

Description

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

Syntax

items() method syntax:

dict.items()
Copy after login

Parameters

##NA.

Return value

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

Example

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

# !/usr/bin/python
# coding=utf-8

dict = {'Google': 'www.google.com', 'Runoob': 'www.runoob.com', '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.runoob.com')]
Google www.google.com
taobao www.taobao.com
Runoob www.runoob.com
Copy after login
The above is all the content of this article, the built-in items function of the dictionary in python. I hope what I said and the examples I gave can be helpful to you.

For more related knowledge, please visit the

Python tutorial column on the php Chinese website.

The above is the detailed content of What is the python items function? How to use it?. 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