Return value of an assignment statement?
7stud
bbxx789_05ss at yahoo.com
Thu Feb 21 16:51:30 EST 2008
On Feb 21, 2:43 pm, mrstephengross <mrstevegr... at gmail.com> wrote:
> Hi all. In C, an assignment statement returns the value assigned. For
> instance:
>
> int x
> int y = (x = 3)
>
> In the above example, (x=3) returns 3, which is assigned to y.
>
> In python, as far as I can tell, assignment statements don't return
> anything:
>
> y = (x = 3)
>
> The above example generates a SyntaxError.
>
> Is this correct? I just want to make sure I've understood the
> semantics.
>
> Thanks,
> --Steve
x = y = 1
print x, y
--output:--
1 1
With parentheses, it looks like python thinks you are trying to do a
boolean == inside the parentheses. It's the same error you get if you
write:
if x = y:
print 'yes'
More information about the Python-list
mailing list