python - append vs. extend -
what's difference between list methods append()
, extend()
?
append
: appends object @ end.
x = [1, 2, 3] x.append([4, 5]) print (x)
gives you: [1, 2, 3, [4, 5]]
extend
: extends list appending elements iterable.
x = [1, 2, 3] x.extend([4, 5]) print (x)
gives you: [1, 2, 3, 4, 5]
Comments
Post a Comment