How does python compare functions?

后端 未结 2 1724
谎友^
谎友^ 2020-11-29 04:58

How come this doesn\'t rise Attribute error? function object doesn\'t have any of the comparison methods. Does it use id() somehow?

fun1 = lambda:x
fun2 = la         


        
2条回答
  •  没有蜡笔的小新
    2020-11-29 05:10

    Function objects do not define their own comparisons or rich comparisons. Instead, they inherit from type objects which implement rich comparisons based on the object's address in memory.

    So yes, it effectively uses addresses just like the built-in id() function does.

    In Python 3, functions are no longer orderable.

提交回复
热议问题