Kaydet (Commit) 8c5e190d authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Issue #28587: Improve list examples in the tutorial

üst 6023d334
...@@ -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 2
>>> a.insert(2, -1) >>> fruits.count('tangerine')
>>> a.append(333) 0
>>> a >>> fruits.index('banana')
[66.25, 333, -1, 333, 1, 1234.5, 333] 3
>>> a.index(333) >>> fruits.index('banana', 4) # Find next banana starting a position 4
1 6
>>> a.index(333, 2) # search for 333 starting at index 2 >>> fruits.reverse()
2 >>> fruits
>>> a.remove(333) ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
>>> a >>> fruits.append('grape')
[66.25, -1, 333, 1, 1234.5, 333] >>> fruits
>>> a.reverse() ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
>>> a >>> fruits.sort()
[333, 1234.5, 1, 333, -1, 66.25] >>> fruits
>>> a.sort() ['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
>>> a >>> fruits.pop()
[-1, 1, 66.25, 333, 333, 1234.5] 'pear'
>>> a.pop()
1234.5
>>> a
[-1, 1, 66.25, 333, 333]
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