[Tutor] Test Question
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Jul 1 14:15:39 CEST 2013
On 1 July 2013 12:01, Dave Angel <davea at davea.name> wrote:
> Third if my_object is something that doesn't equal anything else, such as a
> floating point NAN. Two NANs are not equal, and a NAN is not even equal to
> itself.
Many builtin collection types do an identity 'is' check before an
equality '==' check so nan behaviour depends on whether it is the
exact same nan:
>>> float('nan') in [1, 2, 3, float('nan')]
False
>>> nan = float('nan')
>>> nan in [1, 2, 3, nan]
True
I don't know to what extent that is a deliberate feature or an
optimisation that wasn't fully considered but it at least maintains
the following invariant:
>>> my_sequence = [1, 2, 3, float('nan')]
>>> all(item in my_sequence for item in my_sequence)
True
Oscar
More information about the Tutor
mailing list