Python dictionary functions

Source: Internet
Author: User

Method name Operation

Dict.cleara () Delete all the elements in the dictionary

Dict.copya () Returns a copy of the dictionary (shallow copy)

DICT.FROMKEYSC (SEQ,

Val=none) C creates and returns a new dictionary, with the element in SEQ doing the dictionary key, Val making the word

The initial value for all keys in the code (default is None if this value is not provided)

Dict.get (Key,

Default=none) A pair of key keys in the dictionary dict, returns its corresponding value if the dictionary does not exist in the

Key, the value of default is returned (note that the default value of the parameter is None)

Dict.has_key (Key) returns True if the key (key) exists in the dictionary, otherwise false is returned. In Python2.2

After the version introduces in and not, this method is almost obsolete, but it still provides a

The interface that can work.

Dict.items () Returns a list containing the tuple (key, value) in the dictionary

Dict.keys () Returns a list containing the keys in the dictionary

Dict.iter () d method Iteritems (), Iterkeys (), Itervalues () and their corresponding non-iterative methods

, the difference is that they return an iteration instead of a list.

DICT.POPC (Key

[, default]) C and Method get () similar, if the dictionary key key exists, delete and return Dict[key],

Throws a Keyerror exception if the key key does not exist and does not give the default value.

Dict.setdefault (Key,

Default=none) E is similar to method set (), if the key key is not present in the dictionary, the Dict[key]=default is

It is assigned a value.

Dict.update (DICT2) A adds the key-value pairs of the dictionary dict2 to the dictionary dict

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


This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1721565

Python dictionary functions

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.