Python 2和Python 3中EXEC函数的行为
Python2Python3:
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.0Python3
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]b: 1000000.042
Python2bexecuteexecPython3Python2Python3execPython3
慕标5832272
凤凰求蛊
翻翻过去那场雪
随时随地看视频慕课网APP
相关分类