0

Below is the code in javascript. I need to convert it into Python. Having a multiple switch cases with one return value.:

textOfBetType: function(tip) {
    switch (tip) {
    case "tip1":
    case "tip0":
    case "tip2":
        return "Livewette 0:0"
        //return "Sieger (3-Weg)"
    case "tipOver":
    case "tipUnder":
        return "Über/Unter 2,5";
      }

    return null;
}

I used "if and else" statement in Python.

def text_of_bet_type(self, tip):
        if tip == "tip1" or tip == "tip0" or tip == "tip2":
            return "Livewette 0:0"
        else:
            return 'null';

but is there any other way to do this this..

Nitisha
  • 3
  • 3
  • 1
    Possible duplicate of [Replacements for switch statement in Python?](http://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python) – JRodDynamite Apr 29 '16 at 07:03
  • `def f(x): return { 'a': 1, 'b': 2, }[x]` Using the above statement I need to pass multiple key with one return statement. So how to do that part. – Nitisha Apr 29 '16 at 08:32
  • Instead of the logical or expression you could simply write: if tip in ("tip0", "tip1", "tip2").... – guidot Apr 29 '16 at 08:54

0 Answers0