标签: python exec
代码
a = 2 print("a = {:d}".format(a)) my_dict = {'test_function': lambda x: exec("a = {:d}".format(x))} my_dict['test_function'](3) print("a = {:d}".format(a))
返回
a = 2 a = 2
代替
a = 2 a = 3
我在做什么错了?