+ 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...

16th Dec 2018, 8:39 AM
Adriel Matei
Adriel Matei - avatar
2 ответов
+ 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
16th Dec 2018, 9:13 AM
Kishalaya Saha
Kishalaya Saha - avatar
16th Dec 2018, 10:47 AM
Maninder $ingh
Maninder $ingh - avatar