> > Greg Wilson wrote:
> > One student (a physicist who now does computer graphics) sent me:
> >
> > if x is:
> > expr1, expr2:
> > code using x (which is either val1 or val2)
> > expr3:
> > code using x (which is guaranteed to be val3)
> > else:
> > code using x (which is something else)
> Ka-Ping Yee wrote:
> I like this quite a lot! One question: in that last "else" clause,
> wouldn't "x" be undefined?
(Quick flip through notes): "x is None in the else branch".
Looking at it again, it came up as part of the question "Why isn't
assignment an operator?" The student in question was used to doing:
if (x = foo())
{
body
}
else if (x = bar())
{
body
}
else
{
body
}
and wanted to have something in Python that would (a) provide more
flexibility than a C/C++ case statement, while (b) making it clear
that the alternatives really were mutually exclusive.
I think. Or maybe not. He talked really, really fast...
Greg
> > One student (a physicist who now does computer graphics) sent me:
> >
> > if x is:
> > expr1, expr2:
> > code using x (which is either val1 or val2)
> > expr3:
> > code using x (which is guaranteed to be val3)
> > else:
> > code using x (which is something else)
> Ka-Ping Yee wrote:
> I like this quite a lot! One question: in that last "else" clause,
> wouldn't "x" be undefined?
(Quick flip through notes): "x is None in the else branch".
Looking at it again, it came up as part of the question "Why isn't
assignment an operator?" The student in question was used to doing:
if (x = foo())
{
body
}
else if (x = bar())
{
body
}
else
{
body
}
and wanted to have something in Python that would (a) provide more
flexibility than a C/C++ case statement, while (b) making it clear
that the alternatives really were mutually exclusive.
I think. Or maybe not. He talked really, really fast...
Greg