+ 1

A small clarification needed Is it right?

a="false" b="true" print(a and b) output is true and why?

29th Aug 2017, 5:35 PM
Sai Yerni Akhil
Sai Yerni Akhil - avatar
4 Respostas
+ 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
29th Aug 2017, 5:47 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
29th Aug 2017, 6:14 PM
Gami
Gami - avatar
+ 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
29th Aug 2017, 6:38 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 4
@Baptiste Yup, that's right. My fault :(
29th Aug 2017, 9:21 PM
Gami
Gami - avatar