Toggle

Chris Angelico rosuav at gmail.com
Sun Oct 12 14:43:10 EDT 2014


On Mon, Oct 13, 2014 at 5:38 AM, Tony the Tiger <tony at tiger.invalid> wrote:
>> colour = 'red' if colour == 'blue' else 'blue'
>
> I call that a subtle bug that most likely will jump up and bite your
> behind when you least expect it.

More generally, I'd say that this is solving a (very) slightly
different problem: it's providing a "toggle with default" feature,
where the part after the else is the default. If you don't want a
default, that's a bug. I've known times when that default makes life a
lot easier, in which case it'd be a feature.

ChrisA



More information about the Python-list mailing list