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
Read the manual: 6.3.1 Augmented assignment statements
"target augop expression_list
An augmented assignment evaluates the target (which, u
Alan Gauld wrote:
"Lie Ryan" wrote
I was a bit surprised this doesn't work though:
a, b += k, k
What would you expect?
I expect
a, b += c, d
to be
a += c; b += d
just like
a, b = c, d
to be
a = c; b = d
Remember that
a,b = c,d
is just tuple assignment without using parens (and pare
Ohh, I never thought it this way. Thanks for enlightening.
On Sun, Nov 22, 2009 at 9:52 PM, Alan Gauld wrote:
>
> "Lie Ryan" wrote
>
>
> I was a bit surprised this doesn't work though:
>
>>
>> a, b += k, k
>>
>>
> What would you expect?
> Remember that
>
> a,b = c,d
>
> is just tuple assignment
"Lie Ryan" wrote
I was a bit surprised this doesn't work though:
a, b += k, k
What would you expect?
Remember that
a,b = c,d
is just tuple assignment without using parens (and parens are not part of
the tuple definition)
So using tuples
a,b += k,k
would unwrap as
a,b = (a,b) + (k,k
On Sun, Nov 22, 2009 at 2:30 AM, 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 e
Alan Gauld wrote:
"Shashwat Anand" 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
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
thanks Alan, i was just curious, thats it.
And yeah, simplest is best :)
On Sun, Nov 22, 2009 at 2:38 PM, Alan Gauld wrote:
>
> "Shashwat Anand" 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 av
"Shashwat Anand" 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!
Y
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 statement
10 matches
Mail list logo