python 中list dict tuple的比较

来源:互联网 发布:实施网络攻击的前提 编辑:程序博客网 时间:2024/05/17 03:07

转自于 http://hi.baidu.com/kxw102/blog/item/6c36404789f1cc066a63e598.html

python的list,dict,tuple比较和应用

总结一下:

list是顺序的,可变的。
dictrionary是无顺序的,可变的
tuple是顺序的,不可变的。

 >>> a=((4,"abc"),(2,"efg"),(3,"ghi"))
>>> type(a)
<type 'tuple'>
>>> print list(a)[1]
(2, 'efg')
>>> print dict(a)[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
KeyError: 1
>>> print dict(a)[2]
efg

http://hi.baidu.com/nirenyang/blog/item/d145bf50401f217884352411.html

原创粉丝点击