mutable_sequence.pop() documentation - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: mutable_sequence.pop() documentation (/thread-3367.html) |
mutable_sequence.pop() documentation - Skaperen - May-18-2017 the documentation for the .pop() method for mutable sequences says that the argument to be passed to it is a number in a list. why is that?
RE: mutable_sequence.pop() documentation - micseydel - May-18-2017 That "list" notation is common for indicating that it's optional. So you provide either a number, or nothing. Other readers can see https://docs.python.org/3.7/tutorial/datastructures.html for an example. RE: mutable_sequence.pop() documentation - Skaperen - May-18-2017 so [[]] can mean an optional empty list. or for more fun [[n]] can mean an optional list with n as its only member or a list that can optionally have a member n or be empty.
RE: mutable_sequence.pop() documentation - micseydel - May-18-2017 I'd have to see a real example. RE: mutable_sequence.pop() documentation - Skaperen - May-18-2017 (May-18-2017, 03:48 AM)micseydel Wrote: I'd have to see a real example. how would i do that? i'm just making mixed interpretation of [] ehen there are two of them, one interpreted as a list spec and the other meaning optional. RE: mutable_sequence.pop() documentation - wavic - May-18-2017 You pop(index) out of the sequence >>> l = list(range(1, 21)) >>> l [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] >>> for index, _ in enumerate(l): ... print(l.pop(index+1)) 2 4 6 8 10 12 14 16 18 20 >>> l [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] |