首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Python 学习(三)

继续学习,速度还是太慢了,今天才把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)])

晚上小芒果不开心,哭闹的有点多。

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180620G03ERE00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券