Python dictionary Functions

Source: Internet
Author: User

Python dictionary Functions
Method Name operation dict. cleara () deletes all the elements in the dictionary. copya () returns a copy of the Dictionary (Shortest copy) dict. fromkeysc (seq, val = None) c creates and returns a new dictionary, which uses the elements in seq as the dictionary key, val is the initial value corresponding to all keys in the dictionary (if this value is not provided, the default value is None) dict. get (key, default = None) a pairs the key in the dictionary dict and returns its corresponding value. If this key does not exist in the dictionary, the default value is returned. (Note, the default value is None.) dict. has_key (key) if the key exists in the dictionary, True is returned; otherwise, False is returned. after the in and not in methods are introduced in Python2.2, this method is almost obsolete, but a working interface is still provided. Dict. items () returns a list of tuples containing Dictionary (key, value) pairs (dict. keys () returns a list of dict that contains the dictionary's middle keys. iter () d Method iteritems (), iterkeys (), itervalues () are the same as their non-iterative methods. The difference is that they return an iterator instead of a list. Dict. popc (key [, default]) c is similar to the get () method. If the key in the dictionary exists, delete it and return the dict [key]. If the key does not exist, the default value is not provided, causing a KeyError. Dict. setdefault (key, default = None) e is similar to the method set (). If the key does not exist in the dictionary, dict [key] = default assigns a value to it. Dict. update (dict2) a adds the dictionary dict2 key-value pairs to the dictionary dictdict. values () and returns a list containing all the values in the dictionary.

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.