if语句错误:语法无效,应为缩进b

2024-09-27 22:26:45 发布

您现在位置:Python中文网/ 问答频道 /正文

执行下面的代码时,出现语法错误:

expected an indented block

我已经检查了标签不是像其他线程建议的空格。是什么造成的?在

if wallDirection = '-X':
    xAxis = -buildingSectionWidth

Tags: 代码anif标签block线程建议expected
1条回答
网友
1楼 · 发布于 2024-09-27 22:26:45

首先看What is the difference between an expression and a statement in Python?if语句需要一个表达式作为其条件。在

wallDirection = '-X'是一个语句,它将wallDirection分配给值-X。这里可能需要的表达式是wallDirection == '-X'。测试相等性的运算符是==,而不是{}。在

if wallDirection == '-X':
    xAxis = -buildingSectionWidth

相关问题 更多 >

    热门问题