>From the Python documentation at
https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions

> Small anonymous functions can be created with the lambda
<https://docs.python.org/3/reference/expressions.html#lambda> keyword. This
function returns the sum of its two arguments: lambda a, b: a+b. Lambda
functions can be used wherever function objects are required. They are
syntactically restricted to a single expression. Semantically, they are
just syntactic sugar for a normal function definition.

Thus, in your case the lambda is equivalent to:

def line(x):
    return x + 3

Cheers, Timo

On Sat, Jun 2, 2018 at 1:12 PM Sharan Basappa <sharan.basa...@gmail.com>
wrote:

> Can anyone please tell me what the following line in a python program does:
>
> line = lambda x: x + 3
>
> I have pasted the entire code below for reference:
>
> from scipy.optimize import fsolve
> import numpy as np
> line = lambda x: x + 3
> solution = fsolve(line, -2)
> print solution
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
*Timo Furrer*

https://github.com/timofurrer
tuxt...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to