Dict (dictionary)

Source: Internet
Author: User

Create Dictionary: info = {

"Age": 18,

"Name": "Zhangsan",

"Li": [11,[], (), 22,33,{"K1": "Vv1", "Sex": 0}],

}

(1) The keys of a dictionary can be numbers, strings, tuples, keys cannot be duplicated, otherwise the second key cannot be displayed

(2) Value: info[' age ', Info.get ("age", default): value does not exist with default padding

Difference: info["age" key does not exist then error, get () will not

(3) Clear (), Empty dictionary

(4) copy (), Duplicate dictionary (light copy)

(5) del Info[keys], delete the dictionary element by key

(6) for item in info: Loop to get Key,item as info key

(7) for item in Info.keys (): Loop to get keys

(8) for item in Info.values (): Loop to get value

(9) for k,v in Info.item (): Loop to get key and value

(x) v = dict.fromkeys (list, value), generating a dictionary as a value based on each element of the sequence list as a key,value

(one) Pop (key), delete the element key is key, and return the deleted element

() Popitem (), random Delete, and return key, value key value pair

() SetDefault (key, value), set the value. Key already exists, does not set, returns the current key value, key does not exist set key, value, and returns value

Update ({key1:value1, key2:value2})

or update (key1=value1, key2=value2) to update value values

Dict (dictionary)

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.