Tutorial on returning dictionary element pairs using the items () method in Python

Source: Internet
Author: User

Tutorial on returning dictionary element pairs using the items () method in Python

This article describes how to use the items () method to return dictionary element pairs in Python. It is a basic knowledge of getting started with Python. For more information, see

The items () method returns the list of dictionary (Key, value) tuples

Syntax

The syntax of the items () method is as follows:

?

1

Dict. items ()

Parameters

NA

Return Value

This method returns the list of tuples.

Example

The following example shows how to use the items () method.

?

1

2

3

4

5

#! /Usr/bin/python

 

Dict = {'name': 'zara ', 'age': 7}

 

Print "Value: % s" % dict. items ()

When we run the above program, it will produce the following results:

?

1

Value: [('age', 7), ('name', 'zara ')]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.