Python basics _ type_dict, python basics _ dict

Source: Internet
Author: User

Python basics _ type_dict, python basics _ dict

# The dict dictionary is not as suitable as the key-value dictionary. I don't know how this name came from. It can be used for usernames and passwords, but isn't it too low to use this database?

# Expand with braces {} and separate each element with commas (,). Each element must have key and value, and key and value are separated by colons.

A = {'A': 1, 'B': 2} # 'A', 'B' is key, 1, 2 is value

A. get ('A') # obtain the value corresponding to the key. The result is 1.

A. keys () # obtain all the keys in the dictionary. The result is ['A', 'B'], a list, and intelligence! More intimate!

A. pop ('A') # delete a key element and 1 is displayed. The result is {'B': 2}

B = {'C': 3}

A. update (B) # add another dictionary. The result is {'C': 3, 'B': 2}

A. values () # return all values. The result is [3, 2], a list. It's so intelligent !!! I'm coming again...

A ['B'] # obtain the value corresponding to the key like get. What should we do with get? Well, I don't understand it. I can't understand the good habits of foreigners, it may also have different functions. Please be advised if you know it.

A [1] # the error message does not contain the key 1, so .... Dict cannot be sliced

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.