[Python-Dev] Switch statement

Georg Brandl g.brandl at gmx.net
Wed Jun 21 11:23:19 CEST 2006


Ka-Ping Yee wrote:
> On 2006年6月21日, Phillip J. Eby wrote:
>> Well, EIBTI and all that:
>>>> switch x:
>> case == 1: foo(x)
>> case in S: bar(x)
>>>> It even lines up nicely. :)
>> Hmm, this is rather nice. I can imagine possible use cases for
>> switch x:
> case > 3: foo(x)
> case is y: spam(x)

Ha, a slight reminiscence of BASIC...
> case == z: eggs(x)
>> An interesting use case for which this offers no corresponding
> syntax is
>> case instanceof ClassA: ham(x)
>> which doesn't work because Python spells a type test as
> isinstance(a, b) rather than with an operator. (I suppose
> whether we want it to be an operator might be another
> question to think about for Python 3000.)

FWIW, I like "is a" most, but there's no way to spell this
as one word without confusing readers.
Georg


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /