Python Dictionary (dictionary)

Source: Internet
Author: User

Dictionary (dictionary)

The dictionary has a concept key (key) and the corresponding values (value)

For example:

Phone = {' rom ': 13760413131, ' valley ': 13927434343, ' Helen ': 1355101535}

Features of the dictionary:

1. Define a dictionary with curly braces {}

2. The key and value in each dictionary are concatenated with a colon, indicating that they are a group of

3, in each group behind, comma table separated

How to do the dictionary:

1. Find the Valley Phone

Print (phone[' valley ')

2. Add a new element to the dictionary

phone[' Yellow ']=345

3. Modify the value of an element in the dictionary

phone[' Yellow ']=678

4. Remove an element from the dictionary

Del phone[' [ROM]

5. Empty all the elements in the dictionary at once

Phone.clear ()

6. Delete the dictionary directly

Del phone

Features of the dictionary:

1, in a dictionary, the key is not allowed to appear the same name

2. The key in the dictionary is immutable, so the list cannot be used in the dictionary

Functions and methods of dictionaries

1. CMP (DICT1,DICT2) compares two dictionary elements

2. Len (dict) Number of statistical dictionary elements

3. STR (dict) output dictionary printable string representation

4, type (variable) returns the type of the variable entered, and returns the dictionary type if the variable is a dictionary.

Python Dictionary (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.