Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement Python语句总是在辅助状态下执行_If Statement_Python 3.x_Logic - Fatal编程技术网

If statement Python语句总是在辅助状态下执行

If statement Python语句总是在辅助状态下执行,if-statement,python-3.x,logic,If Statement,Python 3.x,Logic,我有以下条件声明: if (sc == 'Both') and (fc == 'True') or (bc == 'True'): do this if (sc == 'Front') and (fc == 'True'): do this if (sc == 'Back') and (bc == 'True'): do this 问题是第二和第三个子句按预期工作,但是,如果sc等于两者,fc和bc都为false,则此语句仍会执行,我不知道为什么。您写道 if ((

我有以下条件声明:

if (sc == 'Both') and (fc == 'True') or (bc == 'True'):
     do this
if (sc == 'Front') and (fc == 'True'):
     do this
if (sc == 'Back') and (bc == 'True'):
    do this
问题是第二和第三个子句按预期工作,但是,如果sc等于两者,fc和bc都为false,则此语句仍会执行,我不知道为什么。

您写道

if ((sc == 'Both') and (fc == 'True')) or (bc == 'True'):
     do this
if (sc == 'Front') and (fc == 'True'):
     do this
if (sc == 'Back') and (bc == 'True'):
    do this
我想你是说

#                                     or binds weaker than and so it needs brackets
if (sc == 'Both') and ((fc == 'True') or (bc == 'True')):
     do this
if (sc == 'Front') and (fc == 'True'):
     do this
if (sc == 'Back') and (bc == 'True'):
    do this
您可以将
与对数字进行的任何操作相比较弱,因此这也是正确的:

if sc == 'Both' and (fc == 'True' or bc == 'True'):
     do this
if sc == 'Front' and fc == 'True':
     do this
if sc == 'Back' and bc == 'True':
    do this

Python解释器不同意。我怀疑你遗漏了什么<代码>>>>('Both'='Both')和('False'='True')或('False'='True')
False
等待。。。您使用的是字符串(
'False'
)还是布尔值(
False
)?这里的python不这样做。请详细说明您是如何设置这些值的。我认为如果这些值是sc=“Both”,fc=bc=“False”,那么您的第一个示例也不应该包含在if子句中。