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'
 




相关文章:

  • 2021-08-07
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2021-07-08
  • 2021-10-31
猜你喜欢
  • 2021-06-25
  • 2021-12-31
  • 2021-10-08
  • 2021-09-15
  • 2022-02-03
  • 2021-08-29
  • 2021-05-29
相关资源
相似解决方案