surprise: dict.get's default is a positional only parameter!

Cameron Simpson cs at cskk.id.au
Sat Sep 12 00:31:14 EDT 2020


Normally, if one writes a method like this:

    def get(self, k, default=None):

one can call it as foo.get('x',2) or as foo('x',default=2).

But not with dict.get. I'm amazed I've never tripped over this before.  
(Yes, I appreciate that dict is a builtin class written in C.)

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list