本文介绍了“真”,并在Python'假'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行这块code的:

 路径='/ BLA / BLA / BLA如果路径是正确的:
    打印真
其他:
    打印假

和它打印的。我想用Python值对待任何内容的。为什么会出现这种情况?


解决方案

从<一个href=\"http://docs.python.org/reference/ex$p$pssions.html#boolean-operations\">http://docs.python.org/reference/ex$p$pssions.html#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 an if statement), but the expressions '/bla/bla/bla' is True and '/bla/bla/bla' == True will evaluate to False for the reasons in Ignacio's answer.

这篇关于“真”,并在Python'假'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 11:18