[Python-ideas] "else" expression ":"
Greg Ewing
greg.ewing at canterbury.ac.nz
Sun Apr 14 01:07:38 CEST 2013
Peter Norvig wrote:
> Beginners will often write code like this:
>
> if val > 0:
> return +1
> elif val < 0:
> return -1
> elif val == 0:
> return 0
>
Here's an idea to address this. What do you think of the syntax
>
> "else" expression ":"
This will do nothing to help said beginner. He will continue
to write "elif val == 0:", blissfully unaware that there could
be another case that he hasn't thought of. If he had the
presence of mind to realise that, he would have written
something safer in the first place.
--
Greg
More information about the Python-ideas
mailing list