Message348450
From https://docs.python.org/3/tutorial/datastructures.html#more-on-lists :
list.extend(iterable)
Extend the list by appending all the items from the iterable.
Equivalent to a[len(a):] = iterable.
The "equivalent" is not very good. Consider
def gen():
yield 1
yield 2
raise Exception
Using `a.extend(gen())` would mutate `a`. Using slice assignment would still consume the generator, but `a` would not be modified.
I propose a different example to use to describe the behaviour of extend:
for x in iterable:
a.append(x) |
|
Date |
User |
Action |
Args |
2019-07-25 19:47:06 | wim.glenn | set | recipients:
+ wim.glenn, docs@python |
2019-07-25 19:47:06 | wim.glenn | set | messageid: <1564084026.65.0.901156826849.issue37684@roundup.psfhosted.org> |
2019-07-25 19:47:06 | wim.glenn | link | issue37684 messages |
2019-07-25 19:47:06 | wim.glenn | create | |
|