解决三元运算符 报错“SyntaxError: can''t assign to conditional expression”
运行代码:
a=1 b=1 x=1ifa==belsex=0 print(x)
提示错误:
File"test.py",line3 x=aifa==belsex=0 ^ SyntaxError:can'tassigntoconditionalexpression
expression是表达式,就是加减乘除等各种运算符号连接起来的式子(statement是语句,如if语句,while,复制语句等);
三目运算中表达式只能作为左值
修改后:
a=1 b=1 x=1ifa==belse0 print(x)
[ontrue]if[expression]else[onfalse] #PS:ifelse表达式需要完整,例: returncom[2]ifcom[0]==float("-inf")elsecom[0]
以上就是毛票票小编整理的相关内容,希望能够给大家带来帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。