Python while 块中出现语法错误

发布于 2024-12-29 12:11:01 字数 450 浏览 0 评论 0原文

我在以下代码中遇到语法错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丢了幸福的猪 2025-01-05 12:11:01

您的新行供应是否有限,或者您为什么要编写这样的代码?

您的错误在这里,缺少一个 ]

VARFD[[value[0].split("/")[1]]

Is your supply of new lines limited or why are you writing code like this?

Your error is here, one ] is missing:

VARFD[[value[0].split("/")[1]]
无远思近则忧 2025-01-05 12:11:01

您在该行中缺少一个方括号

        if i == 0 and value[0][0].isdigit(): f3["var_%s" %i] = VARFD[[value[0].split("/")[1]]

。但 Python 代码实际上并不应该写得这么密集。空间和光线!

You're missing a square bracket in the

        if i == 0 and value[0][0].isdigit(): f3["var_%s" %i] = VARFD[[value[0].split("/")[1]]

line. But Python code really isn't meant to be this densely written. Space and light!

温柔一刀 2025-01-05 12:11:01

很简单,就像您在 else 之前的行上缺少一个结束括号一样。

VARFD[[value[0].split("/")[1]]

我怀疑表达式应该是

VARFD[value[0].split("/")[1]]

当出现这样的错误时,这几乎是肯定的迹象,表明您应该分解并简化代码:)

It's as simple as that you're missing an end bracket on the line before the else.

VARFD[[value[0].split("/")[1]]

I suspect the expression should be

VARFD[value[0].split("/")[1]]

It's pretty much sure sign that you should break apart and simplify your code when errors like this show up :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文