Python Basic Learning Notes (eight) common dictionary built-in functions and methods

Source: Internet
Author: User
Tags shallow copy

Resources:

1. Basic Python Tutorial

2. http://www.runoob.com/python/python-dictionary.html

3. http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000

Built-in functions for common operations dictionaries:

Serial Number functions and descriptions
1 CMP (Dict1, DICT2)
Compares two dictionary elements.
2 Len (dict)
Calculates the number of dictionary elements, that is, the total number of keys.
3 STR (DICT)
The output dictionary is a printable string representation.
4 Type (variable)
Returns the type of the variable entered and returns the dictionary type if the variable is a dictionary.

Common dictionary self-bringing method:

Serial Number functions and descriptions
1 Radiansdict.clear ()
Delete all elements in a dictionary
2 Radiansdict.copy ()
Returns a shallow copy of a dictionary
3 Radiansdict.fromkeys ()
Create a new dictionary with the keys to the dictionary in sequence seq, Val is the initial value corresponding to all keys in the dictionary
4 Radiansdict.get (Key, Default=none)
Returns the value of the specified key if the value does not return the default value in the dictionary
5 Radiansdict.has_key (Key)
Returns False if the key returns true in the dictionary Dict
6 Radiansdict.items ()
Returns an array of traversed (key, value) tuples as a list
7 Radiansdict.keys ()
Returns a dictionary of all keys in a list
8 Radiansdict.setdefault (Key, Default=none)
Similar to get (), but if the key does not already exist in the dictionary, the key will be added and the value will be set to default
9 Radiansdict.update (DICT2)
Update the key/value pairs of the dictionary dict2 to the Dict
10 Radiansdict.values ()
Returns all values in the dictionary as a list

Python Basic Learning Notes (eight) common dictionary built-in functions and methods

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.