...

/

Nan-reflexivity

Nan-reflexivity

We'll cover the following...

Let’s see what Python thinks about NaN and infinity.

1.

What do you think about these assignments?

Press + to interact
a = float('inf')
b = float('nan')
c = float('-iNf') # These strings are case-insensitive
d = float('nan')

Let’s observe some behaviors in the terminal below:

Terminal 1
Terminal
Loading...

2.

Let’s explore further.

Press + to interact
x = float('nan')
y = x / x
print(y is y) # identity holds
print(y == y) # equality fails of y
print([y] == [y]) # but the equality succeeds for the list containing y

Explanation

  • 'inf'</ ...

...