+ 3
Python function as argument
So, is there a way to pass a function as an argument, without declaring it? for example, if i want to use lambda, i can't print and things like that. What i'm searching for is some sort of thing like in js...
2 Réponses
+ 6
So you're looking for multi-line anonymous function? It can probably be done, but not in a Pythonic way. It's a design choice Guido van Rossum made. Discussing this very topic in an old blog post, he says:
"But the complexity of any proposed solution for this puzzle is immense, to me: it requires the parser (or more precisely, the lexer) to be able to switch back and forth between indent-sensitive and indent-insensitive modes, keeping a stack of previous modes and indentation level. Technically that can all be solved (there's already a stack of indentation levels that could be generalized). But none of that takes away my gut feeling that it is all an elaborate Rube Goldberg contraption."
https://www.artima.com/weblogs/viewpost.jsp?thread=147358
+ 3
Check this similar question is here.
https://stackoverflow.com/questions/6289646/JUMP_LINK__&&__python__&&__JUMP_LINK-function-as-a-function-argument