简体   繁体   English

if语句错误:语法无效,并且预期出现缩进块

[英]if statement error: invalid syntax and expected an indented block

When executing my code below I get a syntax error: 在下面执行我的代码时,出现语法错误:

expected an indented block 预期缩进的块

I have checked the tabs are not spaces as suggested on other threads. 我检查了选项卡是否没有其他线程上建议的空格。 What is causing this? 是什么原因造成的?

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

First see What is the difference between an expression and a statement in Python? 首先看看Python中的表达式和语句有什么区别? An if statement requires an expression as its condition. if语句需要使用表达式作为其条件。

wallDirection = '-X' is a statement that assigns wallDirection to the value -X . wallDirection = '-X'是将wallDirection分配给值-X的语句。 The expression you likely want here is wallDirection == '-X' . 您在此处可能想要的表达式是wallDirection == '-X' The operator that tests for equality is == , not = . 测试相等性的运算符是== ,而不是=

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM