已解決(Python運行報錯)SyntaxError: expression cannot contain assignment, perhaps you meant “==
“?
a fan runpythonQuestion asked when the program prints the multiplication table:
報錯信息:
File "E:/Python學習/2.py", line 3
print(str(a) + "x" + str(i) + "=" = str(i + a) + "\t", end = '')
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
報錯內容翻譯:
語法錯誤:Expressions cannot contain assignments,Probably you meant it“==”?
報錯原因:Bad splicing in the code
Look carefully at his code+
寫成=
符號了:
修改代碼:
for i in range(1, 10):
for a in range(1, i + 1):
print(str(a) + "x" + str(i) + "=" + str(i + a) + "\t", end = '')
print('')
重新運行成功:
本文已收錄於:《告別Bug》專欄
本專欄用於記錄學習和工作中遇到的各種疑難Bug問題及解決思路+解決方法,包括程序安裝、Problems while running the program, etc,訂閱專欄後如遇到其他問題可私聊幫忙解決!!!