The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

BartC bc at freeuk.com
Sat Mar 12 13:30:32 EST 2016


On 12/03/2016 18:07, Marko Rauhamaa wrote:
> BartC <bc at freeuk.com>:
>
>> No it's very easy. In Python terms:
>>
>> def f(): return "One"
>> def g(): return "Two"
>>
>> h=f
>>
>> h() returns "One". Later you do h=g, and h() returns "Two". No need
>> for f and g themselves to be dynamic. h just needs to be a variable.
>
> Well, what do you make of this:
>
>     >>> def f(): return 1
>     ...
>     >>> g = f
>     >>> def f(): return 2
>     ...
>     >>> g()
>     1
>     >>> f()
>     2

def f001(): return 1
f = f001

g = f

def f002(): return 2
f=f002;

print(g())
print(f())

Same results, but now we've agains removed the need for the function 
names (f001 and f002) to be mutable.

-- 
Bartc



More information about the Python-list mailing list