解決三元運算符 報錯“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是表達(dá)式,就是加減乘除等各種運算符號連接起來的式子(statement是語句,如if語句,while,復(fù)制語句等);
三目運算中表達(dá)式只能作為左值
修改后:
a=1 b=1 x=1 if a==b else 0 print(x)
[on true] if [expression] else [on false]
#PS:if else表達(dá)式需要完整,例:
return com[2] if com[0] == float("-inf") else com[0]
以上就是腳本之家小編整理的相關(guān)內(nèi)容,希望能夠給大家?guī)韼椭?/p>
- 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獲取請求傳遞的數(shù)據(jù)解決方法
- express框架,報錯:“Cannot set headers after they are sent to the client”,解決方法總結(jié)
相關(guān)文章
Angular項目里ngsw-config.json文件作用詳解
這篇文章主要為大家介紹了Angular項目里ngsw-config.json文件作用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11
Angularjs中如何使用filterFilter函數(shù)過濾
這篇文章主要介紹了Angularjs中如何使用filterFilter函數(shù)過濾的相關(guān)資料,需要的朋友可以參考下2016-02-02
Angular 4.x中表單Reactive Forms詳解
這篇文章主要介紹了Angular 4.x中表單Reactive Forms的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-04-04
AngularJS中如何使用$http對MongoLab數(shù)據(jù)表進(jìn)行增刪改查
這篇文章主要介紹了AngularJS中如何使用$http對MongoLab數(shù)據(jù)表進(jìn)行增刪改查的相關(guān)資料,需要的朋友可以參考下2016-01-01

