Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 8c5e190

Browse files
committed
Issue python#28587: Improve list examples in the tutorial
1 parent 6023d33 commit 8c5e190

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

Doc/tutorial/datastructures.rst

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,26 @@ objects:
9999

100100
An example that uses most of the list methods::
101101

102-
>>> a = [66.25, 333, 333, 1, 1234.5]
103-
>>> print(a.count(333), a.count(66.25), a.count('x'))
104-
2 1 0
105-
>>> a.insert(2, -1)
106-
>>> a.append(333)
107-
>>> a
108-
[66.25, 333, -1, 333, 1, 1234.5, 333]
109-
>>> a.index(333)
110-
1
111-
>>> a.index(333, 2) # search for 333 starting at index 2
112-
2
113-
>>> a.remove(333)
114-
>>> a
115-
[66.25, -1, 333, 1, 1234.5, 333]
116-
>>> a.reverse()
117-
>>> a
118-
[333, 1234.5, 1, 333, -1, 66.25]
119-
>>> a.sort()
120-
>>> a
121-
[-1, 1, 66.25, 333, 333, 1234.5]
122-
>>> a.pop()
123-
1234.5
124-
>>> a
125-
[-1, 1, 66.25, 333, 333]
102+
>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
103+
>>> fruits.count('apple')
104+
2
105+
>>> fruits.count('tangerine')
106+
0
107+
>>> fruits.index('banana')
108+
3
109+
>>> fruits.index('banana', 4) # Find next banana starting a position 4
110+
6
111+
>>> fruits.reverse()
112+
>>> fruits
113+
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
114+
>>> fruits.append('grape')
115+
>>> fruits
116+
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
117+
>>> fruits.sort()
118+
>>> fruits
119+
['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
120+
>>> fruits.pop()
121+
'pear'
126122

127123
You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that
128124
only modify the list have no return value printed -- they return the default

0 commit comments

Comments
 (0)