[Tutor] Converting string or list to sum
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Jan 29 14:41:42 EST 2004
On Thu, 29 Jan 2004, Iain wrote:
> If I have a sum as a string (e.g. '2+3') or in a list (e.g. [2,'+',3]),
> how can I get the result of the sum?
Hi Iain,
If we had a function that takes three arguments:
calculate(left_hand_side, operator, right_hand_side)
then we might be able to say something like:
###
>>> calculate(2, '+', 3)
5
>>> calculate(42, '-', 43)
-1
###
Is this the sort of thing that you're asking?
Talk to you later!
More information about the Tutor
mailing list