Skip to content

Instantly share code, notes, and snippets.

@Higgs1
Created December 21, 2014 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Higgs1/369c249f7f4bd7ab2244 to your computer and use it in GitHub Desktop.
Save Higgs1/369c249f7f4bd7ab2244 to your computer and use it in GitHub Desktop.
Python switch statement
class switch:
def __init__(_,o):_._,_.o=0,o
def __iter__(_):yield _.__
def __(_,*o):
if _._ or not o:return 1
elif _.o in o:_._=1;return 1
"""
Usage:
import string
c = input('please enter a character: ')
for case in switch(c):
if case(*string.ascii_lowercase):
print("c is lowercase!")
break
if case(*string.ascii_uppercase):
print("c is uppercase!")
break
if case('!', '?', '.'):
print("c is a sentence terminator!")
break
if case():
print("I dunno what c was!")
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment