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

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -