1
my_boolean = bool("Hello")
print(my_boolean)

When I run this code in python, the output is True.What is the reason?

Rakesh
  • 81,458
  • 17
  • 76
  • 113
cemil çelik
  • 79
  • 1
  • 1
  • 2
  • 1
    Possible duplicate of https://stackoverflow.com/questions/18491777/truth-value-of-a-string-in-python – Dani Mesejo Aug 25 '18 at 15:38
  • Strictly speaking you're not converting a value from string to boolean, because you're loosing information, "hello" as input would result in the same output as "bye bye". – Bouke Aug 25 '18 at 18:03

1 Answers1

1

Because it checks if the string is empty:

  • Empty return False
  • Not Empty return True
Norman
  • 435
  • 6
  • 10