python 执行字符串中的python代码

 

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)

 

posted @ 2018-11-16 20:24  anobscureretreat  阅读(1755)  评论(0)    收藏  举报