Dict dictionary table belongs to the mapped data type
Feature: Access to data by key (key) instead of subscript
An unordered collection containing arbitrary objects
Variable length, can be nested arbitrarily
belongs to the "Variable mapping" category
Object reference table (Hash table)
Declaration: D = {} is an empty dictionary table. The dictionary table is a form of {key:value}. A key can only be an immutable element (a mutable type list cannot).
From the picture below you can also see that the Dict dictionary table is an unordered collection. is sorted by the internal hash algorithm.
Key can only be data of immutable type. A mutable type throws an error message
Accessing elements of the Dict dictionary table
cannot be accessed through an index. Otherwise it will be an error. Access to Dict[key]. Key does not exist and throws an error
Access a multi-level dict dictionary table.
Get Value through Get (key). The advantage of get access is that it does not throw an exception when the Key does not exist, but instead returns a none
The parameters after the Get method can be set to the default value returned when not found
Common operations
(1) dict () built-in function, converted to dict dictionary table "When key does not specify a type, the default is string"
(2) Fromkeys (keys) converts a set of data into a key for the Dict dictionary table
(3) in to determine if Key exists
(4) keys () Gets all keys for the Dict dictionary table
(5) VALUES () Gets the value in the Dict dictionary table
(6) items () Gets all the items that return an array of type tuples
(7) Len (dict) Gets the length of the Dict dictionary table
(8) Copy () Duplicate Dict dictionary table
(9) Clear () Empty dict dictionary table
(10) Modify information: Direct assignment or using the update () method
(11) Delete the Del and Pop () method. The Pop () method is to delete the Key:value and return the value values
Pop () method the second parameter returns the value if the deleted Key:value does not exist. Do not use the second parameter, delete the Key:value does not exist will throw an exception
() Popitem () deletes and returns an element of the first tuple type.
Attached: Loop output
Attached: dict dictionary table with function
Python 0 Basic Primer-------dict Dictionary table