Why = = (and not just =)
Peter Otten
__peter__ at web.de
Sun Oct 19 16:34:57 EDT 2003
Joe Green wrote:
> Sorry, I cant help aking stupid questions:
>
> I understand why we need = = in C, but why in Python (or Java),
> surely if you write
> if a=b: pass # syntax error
> it could not possibly mean anything other than what I intended
> (which was of course if a = = b:) ?
I don't particularly like it, but you can chain assignments:
>>> b = 1
>>> a = b = 2
>>> a,b
(2, 2)
>>> a = b == 2
>>> a,b
(True, 2)
>>>
HTH,
Peter
More information about the Python-list
mailing list