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