Byte of Python笔记(六)

Python总统提供了3中数据类型:
  1. List
  2. tuple
  3. dictionary
(一)List
这个类似于C++的数组和Class的和成体,用中括号讲list的元素括起来,以逗号分隔。同时,有可以类似与class那样append,insert等等操作。
同时,list的元素也可以通过index访问,index的起始地址是0。而且Python支持负数地址,即从末尾开始算。
(二)tuple
和list类似,只不过只能被赋值一次,不能修改,用小括号括起来,以及用逗号分隔。
(三)dictionary
这个就和C++的Class很像了,有key和value之分,比如
ab = {'Swaroop': 'swaroop@byteofpython.org',
          'Larry': 'larry@wall.org',
          'Spammer': 'spammer@hotmail.com'
        }
与Class不同的是,访问其中的某一个元素的方法,不是通过dot,而是通过中括号:
ab['Larry'] = 'larry@wall.org.cn'
 




posted on 2011-11-15 16:11  vincenzo.lai  阅读(152)  评论(0编辑  收藏  举报

导航