Python核心编程写到:
“字典是Python语言中的唯一的映射类型。映射类型对象里哈希值(键,key)和指向的对象(值,value)是一对多关系。”
英语原文:
"Dictionaries are the sole mapping type in Python. Mapping objects have a one-to-
many correspondence between hashable values (keys) and the objects they
represent (values)."
按我的理解,key是不可重复的(重复的时候会覆盖原先的值),看起来key和value是一对一的关系,为什么这里说的是一对多关系呢?难道它的意思是映射类型对象是一对多,字典是特殊的一对一映射类型?谢谢!
dict1 = {'name':'a', 'name':'b'}
dict1
{'name': 'b'}
dict1['name']
'b'