Python-dictionary and python dictionary

Source: Internet
Author: User

Python-dictionary and python dictionary

A dictionary is a key-value data type. You can use strokes and letters to View Details of the corresponding page.

Features:
1. dictionary is not required. (If the strings in the dictionary are printed by light, the sorting will not be arranged in order, because the dictionary has no lower mark .)

Basic Syntax:
Info = {

'Stu1101': "TengLan Wu ",

'Stu1102': "LongZe Luola ",

'Stu1103': "XiaoZe Maliya ",

}

Search

Print (info ['stu1101']) # exact search. If not, an error is returned.

Info. get ('stu1108') # equivalent to fuzzy search, return nunl

Print ('stu1103' in info) # Check whether the key has a user

Modify

Info ['stu1101'] = 'burwlands'

Add

Info ['stu1104'] = 'cangjingkong'

Delete

Info. pop ('stu1101 ')

Search for Creation

Info. setdefault ('stu1101', {'www .baidu.com ': [1, 2]}) # first check whether stu1101 value exists. If so, print the original one. If not, create the following one.

Conversion

Info. items () # changed to the list form

Loop

For I in info:

Print (I, info [I])

The items (), keys (), and values () of the Python dictionary return a list.
>>> Dict = {1: 2, 'A': 'B', 'Hello': 'World '}
>>> Dict. values () # return all value values
['B', 2, 'World']
>>> Dict. keys () # return all key values
['A', 1, 'Hello']
>>> Dict. items () # return all values
[('A', 'B'), (1, 2), ('hello', 'World')]

Related Article

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.