以C++为例
#include "stdio.h"
int main(int argc, char ** argv)
{
int i = getchar();
switch(i)
{
case 0:
printf("0 hello");
break;
case 1:
case 2:
printf("1 or 2 hello");
break;
default:
printf("other hello");
break;
}
printf("world\n");
return 0;
}
转化为python
i = int(input("your input"))
for select in [i]:
bOk = None
case = lambda caseVal : bOk != None or caseVal == select
if case(0):
print('0 hello ')
break
if case(1):
bOk = 1
if case(2):
print('1 or 2 hello ')
break
print('other hello ')
print('world\n')