I tried running this piece of code:
path = '/bla/bla/bla'
if path is True:
print "True"
else:
print "False"
And it prints False. I thought Python treats anything with value as True. Why is this happening?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
From 6.11. Boolean operations:
The key phrasing here that I think you are misunderstanding is “interpreted as false” or “interpreted as true”. This does not mean that any of those values are identical to True or False, or even equal to True or False.
The expression
'/bla/bla/bla'will be treated as true where a Boolean expression is expected (like in anifstatement), but the expressions'/bla/bla/bla' is Trueand'/bla/bla/bla' == Truewill evaluate to False for the reasons in Ignacio’s answer.