The 11-day Python Learning record 2

Source: Internet
Author: User

Data Type-Dictionary

A dictionary is a Key-value data type, used as a dictionary of our school, to check the details of the corresponding page by strokes and letters.

Characteristics:

Key-value structure

Key must be hash, must be immutable data type, must be unique

can store any number of values, can be modified, can not be unique

Disordered

Fast Search Speed

Query Info.get () without this key will not error, info[] Without this key, will error, keyerror

Info.values () Remove value

Info.keys () Remove the key value

Info.setdefault () If there is this key, the value of this key is returned, and if there is no key, the dictionary is added

Info.update (b), add the Key-value in dictionary b to the info dictionary, if there is a duplicate key, then overwrite the key value, if there is no repetition, join

Info.items () produces a list of dictionary elements

Info.fromkeys () Generate default dict from a list, there's a pit that can't be explained, try to use less

Multilevel nesting of dictionaries

There are two types of loops:

1.for Key in Info:

Print (Key,info[key])

This method is simple, quick, and often used

2.for k,v in Info.items ():

Print (K,V)

This method will first convert the dictionary into a list, and then loop, execution efficiency is not the first method of high,

The 11-day Python Learning record 2

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.