[Tutor] weird lambda expression -- can someone help me understand how this works
Steven D'Aprano
steve at pearwood.info
Sat Dec 14 05:21:45 CET 2013
On Sat, Dec 14, 2013 at 12:29:54PM +1000, Amit Saha wrote:
> Consider this simple example:
>
> >>> l = lambda x: x**2
> >>> apply(l, (3,))
> 9
The built-in function apply is deprecated in Python 2 and removed in
Python 3. Instead apply, you should use argument unpacking:
l(*(3,))
In this case, it's silly to unpack a tuple of a single value, instead
you should just do this:
l(3)
--
Steven
More information about the Tutor
mailing list