继续学习,速度还是太慢了,今天才把dictionary 数组看完 ,就一点东西。
Dictionary 一些特性
Accessed by key,not offset
Dicionaries are sometimes called associative arragy or hashes. 字典还被称为关系数组或者hashThey associate a set of values with keys,so you can fetch an item out of a dictionary using the key under which you originally stored it.
引用过后,字典里值顺序会打乱,所以只能靠key 不能用位置引用
You shouldn't depend on dictionary key ordering,in either programs or books!字典key不可靠。
Unordered collections of arbitrary objects
Variable-length,heterogeneous,and arbitrarily nestable 可变长度 混杂类型 多种嵌套
Of the category “mutable mapping” 可变映射
Tables of object references(hash tables)
It's an easy way to fill in a default for a key that isn't present and avoid a missing-key error:
D.get('toast',88)
88
Notes:
Sequene operations don't work 是映射不是顺序
Assigning to new indexes adds entries 一个索引一个值
Keys need not always be strings.
Using dictionaries to simulate flexible lists 用字典模拟列表,节省空间
给字典赋值有四种方法
{'name':'mel‘,’age':45} 直接写
用关键字
D={}
D['name']='mel'
D['age']=45
#dict keyword argument
dict(name='mel',age=45)
#dict key/value tuples from
dict([('name','mel'),('age',45)])
晚上小芒果不开心,哭闹的有点多。
领取专属 10元无门槛券
私享最新 技术干货