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

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

2
  • 1
    Possible duplicate of stackoverflow.com/questions/18491777/… Commented Aug 25, 2018 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". Commented Aug 25, 2018 at 18:03

1 Answer 1

1

Because it checks if the string is empty:

  • Empty return False
  • Not Empty return True
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.