user1159454
user1159454

Reputation: 3317

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

Upvotes: 3

Views: 175

Answers (1)

Atticus29
Atticus29

Reputation: 4432

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!

Upvotes: 2

Related Questions