osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Functions help


On Sunday, 23 February 2014 05:43:17 UTC, Scott W Dunning  wrote:
> I had a question regarding functions.  Is there a way to call a function multiple times without recalling it over and over.  Meaning is there a way I can call a function and then add *5 or something like that?
> 

The following answers your question but is probably not a method you want to employ.

from functools import partial

def a(ch):
  print(ch)

def b(x):
  print(x + 10)

[x() for x in [partial(a, 'd'), partial(b, 10)]*5]

Produces

d
14
d
14
d
14
d
14
d
14

--Simon