DEV Community

Bas Steins
Bas Steins

Posted on

A small Python Quiz

Can you guess what value the variable a has to take, so that this program prints A is not equal A!?

if a != a:
    print("A is not equal A!")
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

Collapse
 
variac profile image
Variac •

float('nan')

Collapse
 
mridulnetizen profile image
Euxodous •

That's cool! I'm wondering what's the reason for the same? Please explain

Collapse
 
bascodes profile image
Bas Steins •

Nan stands for “not a number” and comparing two things we know nothing about (other than what they’re not) is not reasonable.

Therefore by definition, nan is not the same as another nan.

Collapse
 
bascodes profile image
Bas Steins •

That’s correct!