Python list初始化

1、基本方法。

lst = [1, 2, 3, 4, 5]

2、初始化连续数字。

>>> lst = [n for n in range(5, 10)]
>>> print(lst)
[5, 6, 7, 8, 9]

3、初始化n个相同值。(两种方式)

>>> lst = ['x' for n in range(5)]
>>> print(lst)
['x', 'x', 'x', 'x', 'x']
>>> lst = ['z']*5
>>> print(lst)
['z', 'z', 'z', 'z', 'z']
>>> lst = [0]*3
>>> print(lst)
[0, 0, 0]


*** walker ***


你可能感兴趣的:(python,初始化,列表)