python-Data Structure-dictionary

Source: Internet
Author: User

1. What is a dictionary?

A dictionary is a data structure that refers to a value by its name, which is called a mapping and is the only built-in mapping type in Python.

2. Why use a dictionary?

A dictionary can easily be traced to its definition (value) by a specific word (key).

3. Creation of dictionaries

A dictionary consists of multiple keys and their corresponding values, and key-value pairs are also referred to as items . The key in the dictionary is unique and the value is not unique.

The dictionary is represented by {}, and the keys and values are separated by: For example:

Phonebook = {' Johny ': ' 12344 ', ' Viga ': ' 342122 ', ' Lily ': ' 534252 '}

4. Dict function of the dictionary

Used to turn other dictionaries or sequences like (keys, values) into dictionaries.

Dictionary = [(' Name ', ' Viga '), (' age ', 24)]

Print (Dict (dictionary))-->{' age ': ' Name ': ' Viga '}

5. Basic operation of the dictionary

The basic operation and sequence of a dictionary are similar:

Len (dictionary): Returns the number of items in the dictionary

Dictionary[key]: Returns the value of the key

Dictionary[key]=value: The value of the key is updated to value

Del Dictionary[key]: Delete key keys

Key in Dictionary: The key is in the dictionary, judging the membership, judging by the key, not the value.

The key of a dictionary can be any immutable type.

  

    

python-Data Structure-dictionary

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.