解决三元运算符 报错“SyntaxError: can''t assign to conditional expression”
作者:小青_龙
在本篇文章里小编给大家整理的是关于python三元运算符 报错“SyntaxError: can't assign to conditional expression”的处理方法,需要的朋友们学习下。
运行代码:
a=1 b=1 x=1 if a==b else x=0 print(x)
提示错误:
File "test.py", line 3 x=a if a==b else x=0 ^ SyntaxError: can't assign to conditional expression
expression是表达式,就是加减乘除等各种运算符号连接起来的式子(statement是语句,如if语句,while,复制语句等);
三目运算中表达式只能作为左值
修改后:
a=1 b=1 x=1 if a==b else 0 print(x)
[on true] if [expression] else [on false] #PS:if else表达式需要完整,例: return com[2] if com[0] == float("-inf") else com[0]
以上就是脚本之家小编整理的相关内容,希望能够给大家带来帮助。
您可能感兴趣的文章:
- node.js使用express-jwt报错:expressJWT is not a function解决
- 解决React报错Expected an assignment or function call and instead saw an expression
- React报错信息之Expected an assignment or function call and instead saw an expression
- MySQL运行报错:“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”解决方法
- 解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
- Express无法通过req.body获取请求传递的数据解决方法
- express框架,报错:“Cannot set headers after they are sent to the client”,解决方法总结