Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Python: create a simple switch statement

Python:  create a simple switch statement
{filelink=16550}

def show(s):
    print s
def switch(ch):
    try:
      {'1': lambda : show("January"),
       '2': lambda : show("February"),
       '3': lambda : show("March"),
       'show': lambda : show("My Name")
      }[ch]()
    except KeyError:
      show("Key not Found")
switch('1')           # January
switch('show')        # MyName
switch('b')           # Key not Found

Users who found this page were searching for:

  • python what is the focus widget
  • how to close a file python
  • message dialog, python
  • changing columns names in JDBC
  • python if is pressed
  • perl iterate through linked list
  • python: convert serial-read string to number
  • HashMap
  • python create text file
  • iterate over dictionary python

No comments yet.

Leave a Comment