SYNTAX ERROR - Can't assign to operator in setting variables

久未见 提交于 2019-12-02 12:16:39

问题


I have this Syntax Error in IDLE:

SyntaxError: can't assign to operator

This then highlights the end of a line, line 2 of the following code:

date              = "Unknown"
day-of-week       = "Unknown"     
time              = "Unknown"
week              = "Unknown"

I would appreciate any help I can get with this :)


回答1:


Python is interpreting day-of-week as "day" minus "of" minus "week". Try using day_of_week instead.

Sample code to show this.

>>> day = 3
>>> of = 2
>>> week = 4
>>> day-of-week
-3



回答2:


"Day-of-week" is an invalid variable name, and you can't use the minus sign on the left side of an assignment operation.

Your code is the equivalent of:

 day - of - week = "unknown"

Try

day_of_week = "unknown"

Instead!



来源:https://stackoverflow.com/questions/32959419/syntax-error-cant-assign-to-operator-in-setting-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!