[Tutor] multiple assignment on one line

Shashwat Anand anand.shashwat at gmail.com
Sun Nov 22 10:12:38 CET 2009


thanks Alan, i was just curious, thats it.
And yeah, simplest is best :)

On Sun, Nov 22, 2009 at 2:38 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "Shashwat Anand" <anand.shashwat at gmail.com> wrote
>
>
>  Can we pack these two statements in one line ?
>> a += k
>> b += k
>>
>
>  of course a,b +=k will not work but is there any such option available?
>>
>
> Not that I'm aware. And when I tried it just to see what happens it killed
> IDLE completely - Window disappeared  and everything!
>
> You could of course do it in one line using a semicolon but it is no more
> concise than using two lines!
>
> a += k; b += k
>
> And you could use a generator expression, but thats even more typing!
>
> a,b = (n+k for n in [a,b])
>
> Sometimes simplest is best...
>
> HTH,
>
> Alan G
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091122/edf56dc4/attachment.htm>


More information about the Tutor mailing list