exec()方法可以执行python的代码,传入的参数为字符串 exec_str = "print('hello world')" exec(exec_str) 执行结果为'hello world' 转载于:https://www.cnblogs.com/chenliang0309/p/10482711.html