jeudi 25 mai 2017

if else python function call or method call

Can we have call methods based on if elif else... example:

if line2[1] = '1': 
    a(line2) 
elif line2[1] = '2': 
    b(line2) 
elif line2[1] = '3': 
    c(line2)

and the list goes on. Can we use maps and call the function. Say

Example of line inputs:

line = ['1','say','Hi']

line = ['2','How','Are']

Code:

def g(line)
   my_map = { '1': a(line),
           '2': b(line),
           '3': c(line, b),
           ......
           and the list goes on
           }


   here if line[0] = '1' call a(line)
        elif line[0] = '2' call b(line)

How do I call function based on the input .

Please send example code if possible

Thanks Rakesh

Aucun commentaire:

Enregistrer un commentaire