Comparison of functions

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Jul 30 09:37:04 EDT 2005


On Sat, 30 Jul 2005 14:20:50 +0200, tiissa wrote:

> Steven D'Aprano wrote:
>> Playing around with comparisons of functions (don't ask), I discovered an
>> interesting bit of unintuitive behaviour:
>> 
>>>>>a = lambda y: y
>>>>>b = lambda y: y
>>>>>a
>> <function <lambda> at 0xf70598ec>
>>>>>b
>> <function <lambda> at 0xf7059844>
>>>>>a < b
>> False
>> 
>> So I'm puzzled about how Python compares the two.
> 
> Seems to me the object addresses are compared in this case. But I'm too 
> lazy to check it in the source. ;)

Strangely enough, I'm lazy enough to not check the source too :-)

Actually, more to the point, I don't read C, so even if I did check the
source, I wouldn't know what it was trying to tell me.

> However, the doc [1] warns you about such comparisons: """Most other
> types compare unequal unless they are the same object; the choice
> whether one object is considered smaller or larger than another one is
> made arbitrarily but consistently within one execution of a program."""

I am aware of that. That's a wart.


-- 
Steven.




More information about the Python-list mailing list