Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A great feature of Javascript is function statements. You can do this:

(function myFunc(){

Which is a way to declare a function and call it without having to refer to it twice. Can that be mimified on Python?

share|improve this question
You've got it the wrong way around. The function in your snippet is used as expression (which contains statements), and function definition being an expression is precisely what one would need to do the same thing in Python. def is a statement in Python. – delnan Mar 31 '12 at 8:56

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):

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.