使用Eval和List理解访问函数中的参数(Python)

时间:2017-02-18 08:01:24

标签: python list-comprehension

为什么这不起作用?

f = lambda A, B:[eval(i) for i in 'AB']

在Python 3中,返回以下错误:

Traceback (most recent call last):
  File "python", line 1, in <module>
  File "python", line 1, in <lambda>
  File "python", line 1, in <listcomp>
  File "<string>", line 1, in <module>
NameError: name 'A' is not defined

尝试f(1, 2)时。但是,该函数肯定会返回[1, 2] ...

0 个答案:

没有答案