dict.get(key, default) evaluates default even if key exists

Matt Ruffalo mruffalo at cs.cmu.edu
Tue Dec 15 23:23:51 EST 2020


On 15/12/20 15:26, Grant Edwards wrote:
> On 2020-12-15, Mark Polesky via Python-list <python-list at python.org> wrote:
>
>> I see. Perhaps counterintuitive,
> I guess that depends on what programming language you normally think
> in. Python's handling of function parameters is exactly what I
> expected, because all of the previous languages I used did the same
> thing.
>
> Purely out of curiosity, what language had you been using that behaved
> otherwise?
>

R comes to mind; arguments can even be defined as functions of other
arguments, and this is evaluated symbolically at call time:

"""
> f = function(x, y = 2 * x) { y }
> f(1)
[1] 2
> f(2)
[1] 4
> f(y = 3)
[1] 3
"""

MMR...


More information about the Python-list mailing list