float identity comparison in Python lambda function
问题 Why does the following happen with Python's lambdas (in both Python 2 and 3)? >>> zero = lambda n: n is 0 >>> zero(0) True >>> zero = lambda n: n is 0.0 >>> zero(0.0) False 回答1: The most common Python implementation store a number of small integers as "constant" or "permanent" objects in a pre-allocated array: see the documentation. So, these numbers can be recongized as identical objects using the is operator. This is not done for floats. If you were to compare the numbers using the equality