Answers for "python evaluate string as code"

8

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
Posted by: Guest on May-31-2020
0

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!
Posted by: Guest on March-01-2021

Code answers related to "python evaluate string as code"

Python Answers by Framework

Browse Popular Code Answers by Language