Post

Append와 extend

append는 리스트 자체가 요소로 들어가고 extend는 리스트를 풀어서 넣는다.

1
2
3
4
5
6
7
8
9
10
11
list1 = []
list1.append([1, 2, 3])
list1.append([4])
list1.append([5])
print(list1) # [[1, 2, 3], [4], [5]] 

list2 = []
list2.extend([1, 2, 3])
list2.extend([4])
list2.extend([5])
print(list2) # [1, 2, 3, 4, 5]
This post is licensed under CC BY 4.0 by the author.

© haedal-uni. Some rights reserved.

Using the Chirpy theme for Jekyll.