How to define a function with an empty body?

P

Peng Yu

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() {
}

Regards,
Peng
 
M

Mel

Peng said:
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..... "empty function"
.... ....
File "<stdin>", line 2

^
IndentationError: expected an indented block.... pass
....


Cheers, Mel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top