Reputation:
I use the IronPython Console when I feel like programming, but it does some wacky stuff. For example:
If a=("X")
it says "Unexpected token '=.' Or this:
If a is ("X"):
print ("Y")
else:
print ("Z")
But it should end after that, it still puts in "...". Why?
Upvotes: 0
Views: 216
Reputation: 7662
First question:
if a=("X"):
is not valid Python code. You probably meant:
if a == ("X"):
For the second one, the REPL (read-eval-print loop - the shell) doesn't know when you're going to end a block until it sees an empty line. For example:
>>> if a == "X":
... print "Y"
... else:
... print "Z"
...
You might still want to enter another statement on the next line. If you leave it blank, the REPL knows that you're done that block and want to start a new one. This is a side-effect of Python's significant whitespace.
Upvotes: 9
Reputation: 6438
It should be:
if x==('x'):
print('x')
This is because the =
is an assignment. ==
is a comparison.
Upvotes: 1