summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-11-22 00:29:50 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-11-22 00:29:50 (GMT)
commit8c5e190d360b9f1a08c9fff249ae80d9c18007d5 (patch)
tree418b189994eee6d6160ea8c222883ea7687cd7eb /Doc
parent6023d334337256c8e3bc0eb11e6952d0e021aec5 (diff)
downloadcpython-8c5e190d360b9f1a08c9fff249ae80d9c18007d5.zip
cpython-8c5e190d360b9f1a08c9fff249ae80d9c18007d5.tar.gz
cpython-8c5e190d360b9f1a08c9fff249ae80d9c18007d5.tar.bz2
Issue #28587: Improve list examples in the tutorial
Diffstat (limited to 'Doc')
-rw-r--r--Doc/tutorial/datastructures.rst44
1 files changed, 20 insertions, 24 deletions
diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst
index 83a1f9b..953a68b 100644
--- a/Doc/tutorial/datastructures.rst
+++ b/Doc/tutorial/datastructures.rst
@@ -99,30 +99,26 @@ objects:
An example that uses most of the list methods::
- >>> a = [66.25, 333, 333, 1, 1234.5]
- >>> print(a.count(333), a.count(66.25), a.count('x'))
- 2 1 0
- >>> a.insert(2, -1)
- >>> a.append(333)
- >>> a
- [66.25, 333, -1, 333, 1, 1234.5, 333]
- >>> a.index(333)
- 1
- >>> a.index(333, 2) # search for 333 starting at index 2
- 2
- >>> a.remove(333)
- >>> a
- [66.25, -1, 333, 1, 1234.5, 333]
- >>> a.reverse()
- >>> a
- [333, 1234.5, 1, 333, -1, 66.25]
- >>> a.sort()
- >>> a
- [-1, 1, 66.25, 333, 333, 1234.5]
- >>> a.pop()
- 1234.5
- >>> a
- [-1, 1, 66.25, 333, 333]
+ >>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
+ >>> fruits.count('apple')
+ 2
+ >>> fruits.count('tangerine')
+ 0
+ >>> fruits.index('banana')
+ 3
+ >>> fruits.index('banana', 4) # Find next banana starting a position 4
+ 6
+ >>> fruits.reverse()
+ >>> fruits
+ ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
+ >>> fruits.append('grape')
+ >>> fruits
+ ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
+ >>> fruits.sort()
+ >>> fruits
+ ['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
+ >>> fruits.pop()
+ 'pear'
You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that
only modify the list have no return value printed -- they return the default