语法错误:语法无效?

编程入门 行业动态 更新时间:2024-10-26 20:30:08
本文介绍了语法错误:语法无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下午好,

我正在用 python 开发一个脚本,当我试图从终止符/终端编译它时,我总是收到这个错误,但我不明白语法错误在哪里?

I am developing a script in python and while I am trying to compile it from the terminator/terminal i always get this error, but I cannot understand where is the syntax error?

文件_case1.py",第 128 行

File "_case1.py", line 128

print ('########################') ^

语法错误:无效语法

然后我只是改变句子的位置,我得到的是..

Then I just change the position of the sentence and what I get is..

print '########################' ^

语法错误:无效语法

有什么问题?

推荐答案

检查 print 行之前的代码是否有错误.这可能是由前一行中的错误引起的;例如:

Check the code before the print line for errors. This can be caused by an error in a previous line; for example:

def x(): y = [ print "hello" x()

这会产生以下错误:

File "E:\Python\test.py", line 14 print "hello" ^ SyntaxError: invalid syntax

当错误明显出现在它之前的行时,y = [.没有更多代码就很难调试,但是如果在打印行之前缺少一些括号或类似的东西,它可能会导致这样的错误.

When clearly the error is in the line before it, y = [. It's tough to debug without more code, but if you have some brackets missing before the print line or something similar it can cause such an error.

更多推荐

语法错误:语法无效?

本文发布于:2023-05-26 19:29:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/265215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   语法错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!