Python 2.7:如何使用列表

 123 In [1]: squares = [1, 4, 9, 16, 25] In [2]: squares Out[2]: [1, 4, 9, 16, 25]

 123456 In [3]: squares[0] Out[3]: 1 In [4]: squares[-1] Out[4]: 25 In [5]: squares[-3:] Out[5]: [9, 16, 25]

 12 In [6]: squares[:] Out[6]: [1, 4, 9, 16, 25]

 12 In [7]: squares + [36, 49, 64, 81, 100] Out[7]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

 123456 In [8]: cubes = [1, 8, 27, 65, 125] In [9]:  4 ** 3 Out[9]: 64 In [10]: cubes[3] = 64 In [11]: cubes Out[11]: [1, 8, 27, 64, 125]

 1234 In [12]: cubes.append(216) In [13]: cubes.append(7 ** 3) In [14]: cubes Out[14]: [1, 8, 27, 64, 125, 216, 343]

 123456789101112 In [15]: letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] In [16]: letters Out[16]: ['a', 'b', 'c', 'd', 'e', 'f', 'g'] In [17]: letters[2:5] = ['C', 'D', 'E'] In [18]: letters Out[18]: ['a', 'b', 'C', 'D', 'E', 'f', 'g'] In [19]: letters[2:5] = [] In [20]:  letters Out[20]: ['a', 'b', 'f', 'g'] In [21]: letters[:] = [] In [22]: letters Out[22]: []

 123 In [23]: letters = ['a', 'b', 'c', 'd'] In [24]: len(letters) Out[24]: 4

 123456789 In [25]: a = ['a', 'b', 'c'] In [26]: n = [1, 2, 3] In [27]: x = [a, n] In [28]: x Out[28]: [['a', 'b', 'c'], [1, 2, 3]] In [29]: x[0] Out[29]: ['a', 'b', 'c'] In [30]: x[0][1] Out[30]: 'b'