Can global variable be passed into Python function?

Neil Cerutti neilc at
Fri Feb 28 14:47:02 CET 2014

On 2014-02-28, Marko Rauhamaa <marko at> wrote:
> Chris Angelico <rosuav at>:
>> Python currently has dispatch tables and if/elif chains, and a
>> strong cultural aversion to switch. You could change that by
>> coming up with some *really* awesome proposal, but you'll be
>> fighting against the tide a bit.
> It's easy have a "cultural aversion" when the language doesn't
> provide the facility.
> Switch statements provide for excellent readability in parsers
> and state machines, for example. They also allow the Python
> compiler to optimize the statement internally unlike long
> if-else chains.

Once you remove all the features of switch that wouldn't fit in
Python, e.g.; fall-through, jumps, breaks; whats left provides
negligible benefit over if-elif-else or dict-dispatch.

A pythonic switch statement doesn't provide enough features to
bother with its implemention.

Check out Go's switch statement for an example of what it might
look like in Python. Except you'd get it without labeled break or
the fallthrough statement. Would you still want to use it?

Neil Cerutti

More information about the Python-list mailing list