python - call list of function using list comprehension -


Can I call a list of functions and use the list comprehension? Return func2 (return): return 2 def func3 (): return 3 FL = [func1, func2, func3] FL [0] () FL [1] (F) [2] ()

I know that I can

  for fl: f ()   

But can I down?

  for fl (f))   

An additional question for those people, if my list is in the function class, for example < / P>

  class F: def __init __ (self): self.a, self.b, self.c = 0,0,0 def func1 (self): self.a + = 1 def func2 (Self): self.b + = 1 def func3 (self): self.c + = 1 fl = [func1, func2, func3] fobj = F () f in fobj.fl: F ()   

Does this work?

Of course you can do FABBIJIN :), though for the class method, , Then an object must be given as argument:

  fobj = f () f fj .fl: f (fobj)   

The object should be given as a callable argument because when you see the definition of metho, d def funcX (self): the method has an argument " self < / Strong> " is

Comments