list是一种有序集合,列表中的数据类型可以不一样。
In [13]: a = ['A', 'B', 'C'] In [14]: a Out[14]: ['A', 'B', 'C'] In [15]: a[0] Out[15]: 'A' In [16]: a[1] Out[16]: 'B' In [22]: a[-1] Out[22]: 'C' In [23]: a[-2] Out[23]: 'B'
In [25]: a.append('D') In [26]: a Out[26]: ['A', 'B', 'C', 'D']
In [27]: a.insert(1, 'B1') In [28]: a Out[28]: ['A', 'B1', 'B', 'C', 'D']
In [31]: a Out[31]: ['A', 'B', 'C', 'D'] In [32]: a.pop() Out[32]: 'D' In [33]: a.pop(1) Out[33]: 'B' In [34]: a Out[34]: ['A', 'C']
In [38]: a Out[38]: ['A', 'B', 'C', 'D'] In [39]: a[3] = 'E' In [40]: a Out[40]: ['A', 'B', 'C', 'E']
In [42]: s Out[42]: ['a', 'b', ['c', 'd'], 'e'] In [43]: s[2][1] Out[43]: 'd'