Python while 块中出现语法错误
我在以下代码中遇到语法错误:
if value[0] == "ta" or "su":
num_var = len(value)
i = 0
while value[i][0] != "-" and i <= num_var:
if i == 0 and value[0][0].isdigit():
f3["var_%s" %i] = VARFD[[value[0].split("/")[1]]
else:
f3["var_%s" %i] = VARFD[[value[0]]
f4["val_%s" %i] = "T"
i += 1
它声称语法错误位于以“else:”开头的行上。有什么问题吗?
I get a syntax error in the following code:
if value[0] == "ta" or "su":
num_var = len(value)
i = 0
while value[i][0] != "-" and i <= num_var:
if i == 0 and value[0][0].isdigit():
f3["var_%s" %i] = VARFD[[value[0].split("/")[1]]
else:
f3["var_%s" %i] = VARFD[[value[0]]
f4["val_%s" %i] = "T"
i += 1
it claims that the syntax error is on line that starts with "else:". What's wrong with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的新行供应是否有限,或者您为什么要编写这样的代码?
您的错误在这里,缺少一个
]
:Is your supply of new lines limited or why are you writing code like this?
Your error is here, one
]
is missing:您在该行中缺少一个方括号
。但 Python 代码实际上并不应该写得这么密集。空间和光线!
You're missing a square bracket in the
line. But Python code really isn't meant to be this densely written. Space and light!
很简单,就像您在 else 之前的行上缺少一个结束括号一样。
我怀疑表达式应该是
当出现这样的错误时,这几乎是肯定的迹象,表明您应该分解并简化代码:)
It's as simple as that you're missing an end bracket on the line before the else.
I suspect the expression should be
It's pretty much sure sign that you should break apart and simplify your code when errors like this show up :)