[Tutor] multiple assignment on one line
Lie Ryan
lie.1296 at gmail.com
Sun Nov 22 10:31:45 CET 2009
Shashwat Anand wrote:
> Ok, this is silly but i want to know is multiple assignment is possible
> in one line using "+=, -=, *= etc" operators on python 2.6.4
>
> like a,b = 0,1 which is equal to
> a = 0
> b = 1
> on seperate lines.
> similarly a = b = 0 which is equal to
> a = 0
> b = 0
> on seperate lines.
>
> Can we pack these two statements in one line ?
> a += k
> b += k
Can we pack them into one line? Sort of...
a += k; b += k
I was a bit surprised this doesn't work though:
a, b += k, k
> Both a,b are incremented by same value 'k'
> ofcourse a,b +=k will not work but is there any such option available?
More information about the Tutor
mailing list