Sunday 15 March 2015

How can I pass functions or operators as arguments to a function in Python? -


... while also leaving it executable within the function.

The idea behind this is that I want to make a conference festival that I have so far:

  def summation (n, bound, operation) : If there is no operation and upper! = 'Inf': g = 0 (n, range + 1) for category = num: g + = num return g other: pass   

but summaries are often for infinite conjugated series Ideally, with the applicable operation for each term, I print conference (0, 'inf', 1 / factorial (n) for every term (for which I use 'inf' ) )) I want to be able to write and continuously E , or DRF W (X): return conference (1, 'INF', (-N) ** (N-1)) / Factal (N)) to get.

The one who comes to my mind is passing the proper arithmetic as a string and then using the exec statement to execute it. But I do not think it will complete the whole thing, and it is probably dangerous to use the exec with the code entered by the user.

No comments:

Post a Comment