Commit f5b074bb authored by Raymond Hettinger's avatar Raymond Hettinger

Issue #28587: Improve list examples in the tutorial

parent 2bf1a787
...@@ -99,30 +99,26 @@ objects: ...@@ -99,30 +99,26 @@ objects:
An example that uses most of the list methods:: An example that uses most of the list methods::
>>> a = [66.25, 333, 333, 1, 1234.5] >>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> print(a.count(333), a.count(66.25), a.count('x')) >>> fruits.count('apple')
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 2
>>> a.remove(333) >>> fruits.count('tangerine')
>>> a 0
[66.25, -1, 333, 1, 1234.5, 333] >>> fruits.index('banana')
>>> a.reverse() 3
>>> a >>> fruits.index('banana', 4) # Find next banana starting a position 4
[333, 1234.5, 1, 333, -1, 66.25] 6
>>> a.sort() >>> fruits.reverse()
>>> a >>> fruits
[-1, 1, 66.25, 333, 333, 1234.5] ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
>>> a.pop() >>> fruits.append('grape')
1234.5 >>> fruits
>>> a ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
[-1, 1, 66.25, 333, 333] >>> 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 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 only modify the list have no return value printed -- they return the default
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment