Search code examples
pythonvariablespython-idle

Weird variable multiple assignment python in IDLE


I'm really confused, I just wrote this

x = 0
y = 42

#Can also be written like this

x, y = 0, 42

print x
print y 

And copy pasted it into IDLE to test it (I'm trying to relearn python along PHP) and then typed "x" and it returned 0. I type y and it gives me an error that it's not defined. When I run this normally though it works fine. What's going on?

Here is the exact error:

Traceback (most recent call last): File "", line 1, in y NameError: name 'y' is not defined


Solution

  • I think your problem might have to do with posting multiple lines of code into IDLE. Take a look at the following:

    Pasting multiple lines into IDLE

    Hope this helps!