A dictionary is the only type of mapping in the Python language. The mapping type does not require a numeric value to be indexed to obtain the corresponding data item from a container. You can use the key (key) to map directly to the value, which is why the mapping is called the reason, mapping, my understanding is the index, the clues can be found behind the back of the person. Dictionaries are one of the most powerful data types in Python.
The first contact with the dictionary or the MapReduce in Hadoop is, in fact, the key pair (Key/value), the so-called index usually refers to the key, and behind the scenes usually refers to the value. Each key corresponds to a value, the main benefit is the facet collation, and the key to find the value is fast and efficient. This is also the most serious of the basic python.
To explain: Create a new empty dictionary dict1, note the curly braces {}, and then Dict2 name and age are key respectively, the corresponding value is DFSJ and 80
Of course, you can also create a dictionary by using the Dict () function.
You can also build a dictionary with the simpler built-in function Fromkeys () function, with the same values in the dictionary. And the default value is null (None). As to which method is good, which method to use depends on your needs or personal hobbies.
The next step is to access the values in the dictionary, where you just need a for loop to traverse its key.
Since the 2.2 version of the keys () method is no longer required, directly write the dictionary name is OK, we will basically general this method.
How to see if a key is a key in the dictionary, now the most common method is the In,not in method, and the return value is a Boolean value. ' DFSJ ' Although it also appears in the dictionary, it is value, not the index value, and In/not in is only used to determine the key. And the way to access a value is Dict[key], just like dict[' name '-----> ' DFSJ '
All of a sudden, I'll be here today.
Python Basic Tutorial series: Seven, Dictionary