What is the difference between the apply() function and a function call using the object of the class?
认为Atom是一个类,其中
- form.name是一个字符串
- convert返回值列表
以下两行有什么区别?
apply(Atom, [form.name] + list([convert(arg, subst) for arg in
list(form.args)]))Atom(form.name, [convert(arg, subst) for arg in form.args])
从文档中,
apply(...)
apply(object[, args[, kwargs]]) -> value
Call a callable object with positional arguments taken from the tuple args,
and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a call() method.
我不明白这两行的区别。我正在尝试在python 3.5中为
1 2 3 | results = apply(foo, [1, 2, 3]) results = foo(*[1, 2, 3]) results = foo(1, 2, 3) |
由于您在python3.5工作,其中
1 | Atom(*([form.name] + [convert(arg, subst) for arg in list(form.args)])) |
1在python2.3中已弃用它!