Python中exec的使用

>>>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

posted on 2016-05-24 19:45  与非朋仔  阅读(1538)  评论(0编辑  收藏  举报

导航