python evaluate string as code code example
Example 1: python execute string
a = """
A = 5
if A > 0 :
print("A Is Positive")
elif A == 0 :
print("A Is Equal To 0")
else :
print("A Is Negative")
"""
exec(a)
>>> A Is Positive
#you can also use eval(string) for asyncio
Example 2: python evaluate string
# Be *extremely* cautious when using eval(), make sure that the user can't
# execute their own code, otherwise it's a very helpful function.
>>> eval("print(\"Hello, World!\")")
Hello, World!