I have a function that I have as a string as follows :-
"def tree(inp):\n\tif inp = 'hello':\n\t\tprint('hello')\n\telse:\n\t\tprint('fake news')"
I want this function to save properly as a function as follows:
def tree(inp):
if inp == 'hello':
print('hello')
else:
print('fake news')
How can I take this string and save it as a function like this without constant copy pasting?
exec, as adefstatement is not an expression (which is whatevalexpects).