This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wim.glenn
Recipients docs@python, wim.glenn
Date 2019-07-25.19:47:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1564084026.65.0.901156826849.issue37684@roundup.psfhosted.org>
In-reply-to
Content
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)
History
Date User Action Args
2019-07-25 19:47:06wim.glennsetrecipients: + wim.glenn, docs@python
2019-07-25 19:47:06wim.glennsetmessageid: <1564084026.65.0.901156826849.issue37684@roundup.psfhosted.org>
2019-07-25 19:47:06wim.glennlinkissue37684 messages
2019-07-25 19:47:06wim.glenncreate