【问题标题】:Invalid Syntax with my "if statement"我的“if 语句”语法无效
【发布时间】:2016-11-09 22:05:26
【问题描述】:

我的 if 语句有问题,我不明白为什么。这里是:

if (first == 1 and second > -1 and third < 1 and (sign(phi[i]) == sign(phi[i-1]) or sign(phi[i]) == sign(phi[i-2])):
foo()

它一直告诉我"invalid syntax"。 你能发现无效的语法吗?

【问题讨论】:

  • 你的缩进是错误的,对于初学者来说。其次,您尝试过什么?
  • 您在末尾缺少括号或开头有太多括号。投票结束是错字。
  • 投票以打字错误/norepro 结束

标签: python syntax


【解决方案1】:

你在最后漏掉了一个括号:

if (first == 1 and second > -1 and third < 1 and (sign(phi[i]) == sign(phi[i-1]) or sign(phi[i]) == sign(phi[i-2]))):
                                                                                                                   ^

【讨论】:

    猜你喜欢
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多