python使用字典实现的switch语句,有需要的朋友可以参考下。
 
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 使用字典实现switch语句
from __future__ import division
x = 1
y = 2
operator = raw_input("Please input + or - or * or / :")
result = {
    "+" : x + y,
    "-" : x - y,
    "*" : x * y,
    "/" : x / y
}
print result.get(operator)