0

Here is my python code:

if 'wishes':
    print("inside")

And here is the console output:

inside

I have found no explanation so far as to why does this return True and if there is a string for which it returns False. I have tried "0" and several others.

guroosh
  • 538
  • 4
  • 18
  • please refer to the documentation https://docs.python.org/3/library/stdtypes.html#truth-value-testing . – hiro protagonist Oct 11 '18 at 05:41
  • Its like the presence of a value is true. Because python has non typed variable the point of this is to sar var = fun() and if that function could return a 'asdfa' or None you can just use if var: to decide what to do if a string was filled in or not. This was confusing for me too coming from a C background – noone392 Oct 11 '18 at 05:45
  • I guess your confusion is easily to resolve:in Python an empty string is considered false, a non-empty string true. The content of the string is not evaluated. `'1' =! 1` – Klaus D. Oct 11 '18 at 06:03

0 Answers0