Typo in Python Tutorial?
Rupert Scammell
rupe at metro.yak.net
Tue Aug 14 15:46:59 EDT 2001
In the Python Tutorial
(http://www.python.org/doc/current/tut/tut.html), Section 5.1, I
noticed that the pop() method for lists is documented as:
pop([i])
Remove the item at the given position in the list, and return it. If
no index is specified, a.pop() returns the last item in the list. The
item is also removed from the list.
I tried the following:
1.5.2 -
>>> mylist = ['one','two','three']
>>> list_item = mylist.pop([0])
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: illegal argument type for built-in operation
2.0 -
>>> mylist = ['one','two','three']
>>> list_item = mylist.pop([0])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: an integer is required
However, in both versions, doing listitem = mylist.pop(0) works the
way I expect, making list_item == 'one', and mylist ==
['two','three'].
Section 5.1.2 in the Tutorial (Using Lists as Queues), however, uses
the mylist.pop(i) notation, which appears to be the correct way of
doing things. Is something funny going on here, or is this a typo in
the documentation?
David Beazley's "Python Essential Reference", p. 22 mentions the
mylist.pop([i]) notation also.
--- Rupert
Rupert Scammell
rupe at metro.yak.net
http://metro.yak.net:8080
More information about the Python-list
mailing list