[Python] list append / extend

데이터 분석/[Python] 기초

[Python] list append / extend

INCHELIN 2021. 8. 3. 13:42
728x90

list형 append vs extend

 

1) list - append( )

x = [1, 2, 3]
y = [4, 5]
x.append(y)
print(x)
# [1, 2, 3, [4, 5]]

2) list - extend( )

x = [1, 2, 3]
y = [4, 5]
x.extend(y)
print(x)
# [1, 2, 3, 4, 5]

 

 

 

 

728x90