Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 357 Bytes

list-operations.md

File metadata and controls

19 lines (16 loc) · 357 Bytes

+运算符可以连接多个列表:

>>> a = [1, 2, 3]
>>> b = [4, 5, 6]
>>> c = a + b
>>> print(c)
[1, 2, 3, 4, 5, 6]

类似的,*运算符对列表进行给定次数的重复:

>>> [0] * 4
[0, 0, 0, 0]
>>> [1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]

第一个例子元素重复了4次,第二个例子重复了3次。