Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 439
user1159454 Avatar asked Nov 26 '25 14:11

user1159454


1 Answers

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!

like image 112
Atticus29 Avatar answered Nov 29 '25 02:11

Atticus29



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!