Problems using samples

Bjorn Pettersen BPettersen at NAREX.com
Wed Jun 26 13:23:38 EDT 2002


> From: Raphael Ribeiro [mailto:gusraan at terra.com.br] 
> 
> 1 x = 8
> 2 y = 4
> 3 v = x - y
> 4
> 5 print v
> 6 if x = y:
> 7	print "Eles são o mesmo valor"
> 8	else:
> 		print "Eles não são iguais , manja?"
> 
> this is my code, it says there's an error in line 6, but i 
> can't find what **** error is that, can anyone help me?

Generally, it's easier to figure out what is going wrong if you give us the stacktrace. In this case:

>>> if x = y:
  File "<stdin>", line 1
    if x = y:
         ^
SyntaxError: invalid syntax

Note that the ^ is pointing to where in the source the error is. x = y is an assignment, assigning the value of y to x. Assignments are not allowed as a test. I'm guessing you wanted to compare the two values to see if they were equal, in that case you need to say

  if x == y:

note the equality operator is spelled ==. A better error message would probably have been helpful...

-- bjorn





More information about the Python-list mailing list