facundo at taniquetil.com.ar
Wed Apr 11 19:07:15 CEST 2007
> Now I know list is a bad name, but for the sake of arguement lets assume its
> not a built in sequence>
It's easier to use another name, than writing all that parragraph, ;)
> 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]).
You're reading it everywhere because it's the correct syntax, ;)
> At first I took that to mean that list.pop(i) would return some type of
> error, but it doesn't.
"i" is enclosed in square brackets because it's optional. So,
list.pop(i) is a correct way to call it, as correct as list.pop().
Take note that list.pop([i]) is *not* the correct way to call it.
I assume you're getting confused by the , asuming that those means a
list. No. Take a look here:
As you see there, when an iterable is needed, it just named different,
syntax do not use brackets to mean "list".
> Now I'm not stupid enough to believe that I'm the first to try:
>>>>list = ['this', 'is', 'an', 'example']
> and have it return the desired effect of:
> ['this', 'an', 'example']
But try this also:
>>> l = ['this', 'is', 'an', 'example']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: an integer is required
More information about the Python-list