Python将if语句与";及;给定语句预期错误

Python将if语句与";及;给定语句预期错误,python,numpy,Python,Numpy,本声明: if 0 not in np.where(~mat.any(axis=1))[0].tolist() and \ if 0 not in np.where(~mat.any(axis=0))[0].tolist(): filled_both = True 是给了我一个错误,但每个人自己似乎都很好。我做错了什么? 运行时没有出现问题: if 0 not in np.where(~mat.any(axis=1

本声明:

        if 0 not in np.where(~mat.any(axis=1))[0].tolist() and \
            if 0 not in np.where(~mat.any(axis=0))[0].tolist():
            filled_both = True
是给了我一个错误,但每个人自己似乎都很好。我做错了什么? 运行时没有出现问题:

        if 0 not in np.where(~mat.any(axis=1))[0].tolist():
            if 0 not in np.where(~mat.any(axis=0))[0].tolist():
                filled_both = True

当您使用
时,如果后面有另一个
,则不应该/不能使用它。它们是互斥的结构(
if…:
是一个语句,其中
..
是一个用于求真的表达式;
将两个表达式连接起来,形成一个新的表达式,一个可能在
if
中使用)。您的第一段代码应该是:

if 0 not in np.where(~mat.any(axis=1))[0].tolist() and \
   0 not in np.where(~mat.any(axis=0))[0].tolist():
    filled_both = True

删除第二行的
if

您可以使用第二行
if
。您可以加入条件,而不是
if
语句。
if语句
不能跟在
后面。您要么想要两个“if”和“no”和“and”,要么想要一个“if”和一个“and”<代码>如果0不在xxx中,0不在yyy中:
因此您得到了一个“语句预期错误”。我以前在python中没有见过这种情况。当我尝试它时,我得到了一个语法错误。堆栈溢出不是为了取代现有的教程和文档。返回布尔表达式教程,学习如何使用
以及
。基本问题在标题中:语句没有
运算符。