>>>globals = {‘x‘:7, .....: ‘y‘:10, .....: ‘names‘:[‘aa‘,‘bb‘,‘cc‘] .....: } >>>locals = {} >>>a = eval("3*x+4*y",globals,locals) >>>print a 61 >>>exec("for i in names: print i",globals,locals) aa bb cc
时间: 2024-10-11 19:40:37
>>>globals = {‘x‘:7, .....: ‘y‘:10, .....: ‘names‘:[‘aa‘,‘bb‘,‘cc‘] .....: } >>>locals = {} >>>a = eval("3*x+4*y",globals,locals) >>>print a 61 >>>exec("for i in names: print i",globals,locals) aa bb cc