[Python-ideas] Add "default" kwarg to list.pop()

Steven D'Aprano steve at pearwood.info
Wed Oct 31 07:21:21 EDT 2018

On Wed, Oct 31, 2018 at 09:31:37PM +1100, Chris Angelico wrote:

> > I don't think I would agree with a broad rule "anything that raises can
> > return a default value" -- I don't think it makes sense to have, let's
> > say, len(obj, default=2). But on a case-by-case basis, it works for me.
> And that's exactly why a broad rule of "anything that raises can be
> wrapped in a catcher" does make sense. Hence it may not be the same
> thing, but it is an alternative solution that doesn't require
> specifically angling for consistency.

True. I'm not arguing against the earlier PEP, I was in favour of it 
too. But even if we had exception-catching expressions, it would still 
make sense to add a default value to list.pop and perhaps a list.get 
method too.


More information about the Python-ideas mailing list