I have 2 variables: x="null" and y=3
Following which I execute the command below:
if(x and y):
print 'True'
Output:True
I am looking for guidance to understand this behavior better.
The answer to this question fixed my issue Most elegant way to check if the string is empty in Python?
But I want to understand the behavior of this. I want to know how an AND of "null" and a numeric value of 3 returns in 3 which in turn results in truthify value.
Noneor'', the empty string?Trueboolean value, in the same way that any int which is not0. So,"null"is just a string like any other, it is different fromNone."null"has no special significance in Python itself, although of course you are free to give it special significance in your own code. Note that the JSON module will translate"null"in a JSON object toNone, and vice versa; thusimport json;print(json.loads('null'))printsNone.