Introduce copy by slicing, used in later chapters.

This commit is contained in:
Georg Brandl 2010-03-21 09:17:41 +00:00
parent d1068be653
commit 0fcd882101

View file

@ -523,6 +523,12 @@ concatenated and so on::
>>> 3*a[:3] + ['Boo!']
['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boo!']
All slice operations return a new list containing the requested elements. This
means that the following slice returns a shallow copy of the list *a*::
>>> a[:]
['spam', 'eggs', 100, 1234]
Unlike strings, which are *immutable*, it is possible to change individual
elements of a list::