pop() clarification

Scott s_broscious at comcast.net
Wed Apr 11 18:44:17 CEST 2007


As said before I'm new to programming, and I need in depth explaination to 
understand everything the way I want to know it, call it a personality quirk 
;p.

With pop() you remove the last element of a list and return its value:

Now I know list is a bad name, but for the sake of arguement lets assume its 
not a built in sequence>

>>>list = ['this', 'is', 'an', 'example']
>>>list.pop()
'example'
>>>list
['this', 'is', 'an']

I understand all that.  What I don't understand is why all the documentation 
I see says, "When removing a specific element from a list using pop() it 
must be in this format: list.pop([i]).
At first I took that to mean that list.pop(i) would return some type of 
error, but it doesn't.
I can't find any documentation saying that this rule that I keep reading 
about (again list.pop([i]) ) is the only format to use when removing a 
specific element because......with the explaination to follow.

Now I'm not stupid enough to believe that I'm the first to try:
>>>list = ['this', 'is', 'an', 'example']
>>>list.pop(1)
and have it return the desired effect of:
'is'
>>>list
['this', 'an', 'example']


I guess simplistically all I'm asking is:  Is this just a community agreed 
upon rule for readability purposes? or Is it a rule that's in place for a 
reason I'll learn later on?  Please keep in mind my intro sentence to this 
post.  I would like a very detailed explaination, or at least a link to a 
very detailed expression.  ONLY....of course....if the explaination isn't, 
well it just is because we all agreed to use it that way.  That explaination 
I'll understand and except, but with a bit of dissatisfaction. 





More information about the Python-list mailing list