Python Learning Notes (5)--Dictionary of data Structures Dict

Source: Internet
Author: User

Dictionary (dict)

Definition: Set of key-value pairs

Initialize: {}, {' 1 ': ' abc ', ' 2 ': ' Def '}

1. Add: Direct assignment of single data

Update (DICT2) ---Add dict2 elements to the dict, which overrides the key values in the dict when repeated

  

  

2. Delete:pop (key, [default]) ---If the dictionary key key exists, delete and return Dict[key], if not present, and do not give the default value, throw Keyerror exception

     popitem () ---Delete any key-value pairs and return the key-value pair, which generates an exception if the dictionary is empty Keyerror

     Clear ()--- slightly

  

3. Query:get (Key,[default]) ---Return the dictionary dict key key corresponding value, if this key is not present in the dictionary, returns the value of default (default defaults to None)

      items () ---Returns a list that contains a tuple (key, value) in the dictionary

      keys () ---Returns a list that contains all the keys in the dictionary

      values () ---Returns a list that contains all the values in the dictionary

   

4. Modify: There is no direct modification of the corresponding elements of the method, directly assign the value can be

Python Learning Notes (5)--Dictionary of data Structures Dict

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.