---
# System prepended metadata

title: append & extend
tags: [python語法]

---

# append & extend
###### tags: `python語法`

List.extend(iterable) 將每個 iterator 加入 list

```python=
xx = list(range(5))
xx
[0, 1, 2, 3, 4]

yy = list(range(2))
yy
[0, 1]

xx.extend(yy)
xx
[0, 1, 2, 3, 4, 0, 1]
```

List.append(object) 將 object 加入 list

```python=
xx = list(range(5))
xx
[0, 1, 2, 3, 4]

yy = list(range(2))
yy
[0, 1]

xx.append(yy)
xx
[0, 1, 2, 3, 4, [0, 1]]
```