Peng Yu wrote: > Hi, > > I want to define a function without anything in it body. In C++, I can > do something like the following because I can use "{}" to denote an > empty function body. Since python use indentation, I am not sure how > to do it. Can somebody let me know how to do it in python? > > void f() { > }
Syntactically, there has to be something in the function definition. It can be a `pass` statement, or a doc string, though: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): ... "empty function" ... >>> f() >>> print f() None >>> def g(): ... File "<stdin>", line 2 ^ IndentationError: expected an indented block >>> def h(): ... pass ... >>> print h() None >>> Cheers, Mel. -- http://mail.python.org/mailman/listinfo/python-list