首页 >> js开发 >> js解决三元运算符 报错“SyntaxError: can''t assign to conditional expression”js大全
js解决三元运算符 报错“SyntaxError: can''t assign to conditional expression”js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
运行代码:
a=1
b=1
x=1 if a==b else x=0
print(x)
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
File "test.py", line 3
x=a if a==b else x=0
^
SyntaxError: can't assign to conditional expressionexpression是表达式,就是加减乘除等各种运算符号连接起来的式子(statement是语句,如if语句,while,复制语句等);三目运算中表达式只能作为左值三目运算中表达式只能作为左值修改后:修改后:
a=1
b=1
x=1 if a==b else 0
print(x)
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]
[on true] if [expression] else [on false]
#PS:if else表达式需要完整,例:
return com[2] if com[0] == float("-inf") else com[0]以上就是小编整理的相关内容,希望能够给大家带来帮助。
a=1
b=1
x=1 if a==b else x=0
print(x)
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
File "test.py", line 3
x=a if a==b else x=0
^
SyntaxError: can't assign to conditional expressionexpression是表达式,就是加减乘除等各种运算符号连接起来的式子(statement是语句,如if语句,while,复制语句等);三目运算中表达式只能作为左值三目运算中表达式只能作为左值修改后:修改后:
a=1
b=1
x=1 if a==b else 0
print(x)
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]
[on true] if [expression] else [on false]
#PS:if else表达式需要完整,例:
return com[2] if com[0] == float("-inf") else com[0]以上就是小编整理的相关内容,希望能够给大家带来帮助。