Python Exercise: Execute a string containing Python code
Python Functions: Exercise - 18 with Solution
Write a Python program to execute a string containing Python code.
mycode = 'print("hello world")' code = """ def mutiply(x,y): return x*y print('Multiply of 2 and 3 is: ',mutiply(2,3)) """ exec(mycode) exec(code)
hello world Multiply of 2 and 3 is: 6
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?