+ 1
A small clarification needed Is it right?
a="false" b="true" print(a and b) output is true and why?
4 Antworten
+ 5
They are both strings objects.
a and b will return true if both objects are not None
Note the difference:
a=False
b=True
print(a and b) // outputs False
+ 5
Every value or object which is not None and False is a "truthy" value. Every "truthy" value is evaluated as True. False is different from the object string "false". Because both a and b are strings, they are truthy and they evaluate as True.
+ 4
Not exactly true @Gami, this is python, not Ruby
"" aka the empty string is considered false
[] aka the empty list is also considered false
0 also
+ 4
@Baptiste Yup, that's right. My fault :(