diff options
author | Georg Brandl <georg@python.org> | 2006-04-13 08:04:56 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-04-13 08:04:56 (GMT) |
commit | 9d548374e45969e5fea3480d47a7bd3067486719 (patch) | |
tree | fe68a2a6761dc3d377c9049a90ff1fff70c42d10 | |
parent | 7f573f7319f070d47565a2a37d659611ee844dd5 (diff) | |
download | cpython-9d548374e45969e5fea3480d47a7bd3067486719.zip cpython-9d548374e45969e5fea3480d47a7bd3067486719.tar.gz cpython-9d548374e45969e5fea3480d47a7bd3067486719.tar.bz2 |
Add two entries about how to actually clear a list.
-rw-r--r-- | Doc/tut/tut.tex | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index 78e03d5..78f5b1c 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -1012,7 +1012,7 @@ individual elements of a list: \end{verbatim} Assignment to slices is also possible, and this can even change the size -of the list: +of the list or clear it entirely: \begin{verbatim} >>> # Replace some items: @@ -1027,9 +1027,14 @@ of the list: ... a[1:1] = ['bletch', 'xyzzy'] >>> a [123, 'bletch', 'xyzzy', 1234] ->>> a[:0] = a # Insert (a copy of) itself at the beginning +>>> # Insert (a copy of) itself at the beginning +>>> a[:0] = a >>> a [123, 'bletch', 'xyzzy', 1234, 123, 'bletch', 'xyzzy', 1234] +>>> # Clear the list: replace all items with an empty list +>>> a[:] = [] +>>> a +[] \end{verbatim} The built-in function \function{len()} also applies to lists: @@ -2011,9 +2016,9 @@ applied to complex expressions and nested functions: There is a way to remove an item from a list given its index instead of its value: the \keyword{del} statement. This differs from the \method{pop()}) method which returns a value. The \keyword{del} -statement can also be used to -remove slices from a list (which we did earlier by assignment of an -empty list to the slice). For example: +statement can also be used to remove slices from a list or clear the +entire list (which we did earlier by assignment of an empty list to +the slice). For example: \begin{verbatim} >>> a = [-1, 1, 66.25, 333, 333, 1234.5] @@ -2023,6 +2028,9 @@ empty list to the slice). For example: >>> del a[2:4] >>> a [1, 66.25, 1234.5] +>>> del a[:] +>>> a +[] \end{verbatim} \keyword{del} can also be used to delete entire variables: |