A great feature of Javascript is function statements. You can do this:
(function myFunc(){
doSomething();
doSomethingElse();
})();
Which is a way to declare a function and call it without having to refer to it twice. Can that be mimified on Python?
1 Answer 1
Python does not have this syntax for functions. It does, however, support the lambda syntax which can be used in this way. However, a lambda is an expression and not a statement, so it is limited.
(lambda x: x*x)(10)
would return 100
When this feature is needed, just use the def
statement to define a function
...
def tmp(x,y):
foo(x);
foo(y);
tmp(12,24)
...
def
is a statement in Python.