What's wrong with this code?

Emile van Sebille emile at fenx.com
Mon Jul 23 11:36:19 EDT 2012


On 7/23/2012 7:50 AM Stone Li said...
> I'm totally confused by this code:
>
> Code:
>
>     a = None
>     b = None
>     c = None
>     d = None
>     x = [[a,b],
>           [c,d]]
>     e,f = x[1]
>     print e,f

This prints the first None,None

>     c = 1
>     d = 2
>     print e,f

And nothing has happened to e or f, so this is the second None,None

Why do you expect 1,2?

Emile



>     e = 1
>     f = 2
>     print c,d
>
> Output:
>
>     None None
>     None None
>     1 2
>
>
> I'm expecting the code as:
>
>     None None
>     1 2
>     1 2
>
>
> What's wrong?
> And this question made my GUI program totally out of control.
> Thanks
>
>






More information about the Python-list mailing list