1

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 :)

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • 1
    Possible duplicate of [Why python does not allow hyphens](http://stackoverflow.com/questions/2064329/why-python-does-not-allow-hyphens) – idjaw Oct 05 '15 at 23:28

2 Answers2

5

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
Elipzer
  • 901
  • 6
  • 22
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!

Kyle Pittman
  • 2,858
  • 1
  • 30
  • 38