Inge
New Coder
Let's say a (sanitized) user defined math expression (such as x1 + x2 * x3), with up to 9 variables xi, is my input, so i'd have:
In python, i can define a function that executes this code, like this:
You can't do this in some other languages, so my questions are:
Python:
input_str = "x1 + x2 * x3"
Python:
func_def_str = """
global calc_func
def calc_func(x1,x2,x3):
return x1 + x2 * x3"""
exec(func_def_str)
You can't do this in some other languages, so my questions are:
- What is this feature called?
- In what other languages can you do something like this? (without having to hack a compiler or something like that)
Last edited: