# 认为a1是全局的
a1 = 100
def fun():
global a1
a1 = 300
print(a1)
print("I am in fun")
# a2的作用范围是fun
a2 = 99
print(a2)
print(a1)
fun()
语法:
eval(string_code, globals=None, locals=None)
语法:
exec(string_code, globals=None, locals=None)
x = 100
y = 200
z1 = x + y
z2 = eval("x+y")
print(z1)
print(z2)
c =eval("print(x,y)")
原文:http://blog.51cto.com/14083201/2336142