简体   繁体   English

语法错误-无法在设置变量中分配给运算符

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

I have this Syntax Error in IDLE: 我在IDLE中有此语法错误:

SyntaxError: can't assign to operator 语法错误:无法分配给运算符

This then highlights the end of a line, line 2 of the following code: 然后突出显示以下代码的第2行:

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

I would appreciate any help I can get with this :) 我将不胜感激:)

Python is interpreting day-of-week as "day" minus "of" minus "week". Python将day-of-week中的某天解释为“天”减去“中的”再减去“周”。 Try using day_of_week instead. 尝试改用day_of_week

Sample code to show this. 示例代码展示了这一点。

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

"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! 代替!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM