Dictionaries
摘要
There are many parallels between lists and dictionaries. Like lists, dictionaries allow several, even many, values to be stored in one variable. Each element in a list has a unique integer index, and these integer indices must increase sequentially from zero. Similarly, each value in a dictionary has a unique key, but a dictionary’s keys are more flexible than a list’s indices. A dictionary’s keys can be integers. They can also be floating-point numbers or strings. When the keys are numeric, they do not have to start from zero, nor do they have to be sequential. When the keys are strings, they can be any combination of characters, including the empty string. All of the keys in a dictionary must be distinct, just as all of the indices in a list are distinct.