list.append([1,2]) will add the two element list as the next
element of the list.
list.extend([1,2]) is equivalent to list = list + [1, 2]
and the result is that each element of the added list
becomes it's own new element in the original list.
Is that the only difference?
From the manual:
s.extend(x) | same as s[len(s):len(s)] = x
But: (python 2.5.2)
[1, 2, 3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only assign an iterable
Also, what is the difference between list[x:x] and list[x]?
[1, 2, 3, 4]
** Posted from http://www.teranews.com **
element of the list.
list.extend([1,2]) is equivalent to list = list + [1, 2]
and the result is that each element of the added list
becomes it's own new element in the original list.
Is that the only difference?
From the manual:
s.extend(x) | same as s[len(s):len(s)] = x
But: (python 2.5.2)
>>a
>>a[len(a):len(a)] = 4
File "<stdin>", line 1, in <module>
TypeError: can only assign an iterable
>>>
>>a[3:3] = [4]
>>a
>>a
** Posted from http://www.teranews.com **
Comment