What is the benefit of this ' : ' in this code? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What is the benefit of this ' : ' in this code?

def my_func(f, arg): return f(arg) šŸ‘‡ my_func(lambda x: 2*x*x, 5)

23rd May 2018, 5:30 PM
Omar
Omar - avatar
2 Respostas
+ 2
The lambda is just a function, like those you define with "def". They just don't have a name. Before the colon (:) you put all the parameters (like with "def"), after it you put what the function does. In other words, def foo(x, y): return x + y and foo = lambda x, y: x + y are more or less the same thing.
23rd May 2018, 5:36 PM
Schindlabua
Schindlabua - avatar
0
thank u allā˜ŗ
23rd May 2018, 5:46 PM
Omar
Omar - avatar