问题
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