Python Forum
Why is bool(float("nan")) == True?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is bool(float("nan")) == True?
#3
The bool class can be used to type cast a string into a bool. An empty string will return False:

empty_string = ''
bool(empty_string)
A non-empty string returns True:

non_empty_string = 'nan'
bool(non_empty_string)
The bool class can be used to type cast a float into a bool. A float of value 0.0 will return False:

bool(0.0)
Any other float returns True:

bool(0.1)
bool(float('nan'))
And the following is True:

float('nan') != 0.0
RockBlok likes this post
Reply


Messages In This Thread
RE: Why is bool(float("nan")) == True? - by philipyip - Dec-30-2023, 12:54 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020