+ 3
Is there a Python equivalent to the 'switch' statement in Javascript?
As the question says, is there a way to treat multiple elif statements by using something like the 'switch' statement in Javascript? Thanks, folks.
1 Resposta
+ 17
No... But you can use dictionaries instead..
a = 4
dict = {4:5, 6:7}
print(dict[a])
is the equivalent in JS
switch(a) {
  case 4:
    return 5
    break
  case 6:
    return 7
    break
  default:
    break
}
However, if you want something similar to switch, this link might be helpful
http://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-JUMP_LINK__&&__python__&&__JUMP_LINK



