Python 2和Python 3中EXEC函数的行为
Python2
Python3
:
from sys import versionprint(version)def execute(a, st): b = 42 exec("b = {}\nprint('b:', b)".format(st)) print(b)a = 1.execute(a, "1.E6*a")
Python2
2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]('b:', 1000000.0)1000000.0
Python3
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]b: 1000000.042
Python2
b
execute
exec
Python3
Python2
Python3
exec
Python3
凤凰求蛊
翻翻过去那场雪
相关分类