Use exec
:
>>> exec("""def a(x):
... return x+1""")
>>> a(2)
3
More Related Contents:
- How function is getting called without defining in python [closed]
- Check if input is empty
- Why does my recursive function return None?
- Call a function from another file?
- How to get a function name as a string?
- Determine function name from within that function (without using traceback)
- How to plot multiple functions on the same figure, in Matplotlib?
- Best way to check function arguments? [closed]
- How are Python in-place operator functions different than the standard operator functions?
- Builtin function not working with Spyder
- How do Python functions handle the types of parameters that you pass in?
- How do I define a function with optional arguments?
- How to access a function inside a function?
- Run PowerShell function from Python script
- Do something every x (milli)seconds in pygame
- Declare function at end of file in Python [duplicate]
- Set function signature in Python
- How to execute a function asynchronously every 60 seconds in Python?
- How do you calculate program run time in python? [duplicate]
- How can I redirect print output of a function in python [duplicate]
- How to pickle a python function with its dependencies?
- Check if two Python functions are equal
- How can I use `return` to get back multiple values from a loop? Can I put them in a list?
- What is first class function in Python
- How does using a function (callback) as an argument to another function work in Python?
- How do nested functions work in Python?
- Python convert decimal to hex
- Use a string to call function in Python [duplicate]
- Are functions objects in Python?
- Defining a default argument as a global variable