Thursday, October 20, 2016

Using lambda to define simple constants

>>>  One = lambda : 1
>>>  One
<function <lambda> at 0x037C1468>
>>>  print(One())
1
>>>  One()
1
>>>  One
<function <lambda> at 0x037C1468>
>>>

A function call! Well, it has no arguments, the work needed for the interpreter is about the same. A compiler van work the tree and resolve it to n immediate integer.

No comments: