How to define a function with an empty body?

Albert Hopkins marduk at letterboxes.org
Sun Sep 13 10:04:13 EDT 2009


On Sat, 2009-09-12 at 22:37 -0500, 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() {
> }
> 

Surprised no one has mentioned this yet, but since it's a function, and
in python all functions return values (whether explicitly or implicitly,
a simple "return" works and, to me, does much more to inform the reader
that "this function does nothing".

def f():
    return





More information about the Python-list mailing list