完美解决丨 - [SyntaxError: invalid syntax](#SyntaxError-invalid-syntax)

简介: 完美解决丨 - [SyntaxError: invalid syntax](#SyntaxError-invalid-syntax)


报错名称

SyntaxError: invalid syntax

错误原因:

  • print() 函数在 python3 中需要加 (),在 python2 中不需要加
  • 解决办法:
  • 设置 pycharm 的 python 解释器为 python3
  • setting - project - project interpreter - 选择 python3 - ok
  • 修改环境变量,在 pycharm 中可以设置环境变量,设置该环境变量的方法为:
  • setting - project - project interpreter - 点击右上角的环境变量设置按钮 - 添加一个变量,变量名为 PYTHONIOENCODING,变量值为 UTF8,点击 ok
  • 在命令行中,执行命令:
    ``` set PYTHONIOENCODING=UTF8 ```

NameError: name 'xx' is not defined

错误原因:

  • 在 python 中,变量名不能以数字开头
  • 解决办法:
  • 修改变量名,变量名只能包含数字、字母、下划线、汉字、函数名

IndentationError: expected an indented block

错误原因:

  • python 的缩进问题
  • 解决办法:
  • 将需要缩进的行前的空格删除


相关文章
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
|
6月前
|
JSON JavaScript 前端开发
Uncaught SyntaxError: Invalid or unexpected token
Uncaught SyntaxError: Invalid or unexpected token
84 0
|
8月前
|
Python
SyntaxError :invalid syntax错误解决办法
SyntaxError :invalid syntax错误解决办法
1978 1
|
9月前
|
IDE 搜索推荐 开发工具
|
SQL Java 数据库连接
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
249 0
|
9月前
|
Python
完美解决丨SyntaxError: invalid syntax
完美解决丨SyntaxError: invalid syntax
error C2041: illegal digit ‘9‘ for base ‘8‘ | error C2059: syntax error: ‘bad suffix on number‘
error C2041: illegal digit ‘9‘ for base ‘8‘ | error C2059: syntax error: ‘bad suffix on number‘
168 0
|
Dart 前端开发 JavaScript
Syntax Error: TypeError: this.getOptions is not a function
Syntax Error: TypeError: this.getOptions is not a function
579 0
Syntax Error: TypeError: this.getOptions is not a function
|
C语言
error: implicit declaration of function ‘VerifyFixClassname‘ is invalid in C99 [-Werror,-Wimplicit-f
error: implicit declaration of function ‘VerifyFixClassname‘ is invalid in C99 [-Werror,-Wimplicit-f
166 0
error: invalid argument ‘-std=gnu++98‘ not allowed with ‘C‘
error: invalid argument ‘-std=gnu++98‘ not allowed with ‘C‘
140 0