Why indentation is use to denote block of code?

Chris Rebert clp2 at rebertia.com
Sun Sep 13 18:15:40 EDT 2009


On Sun, Sep 13, 2009 at 3:12 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
> Hi,
>
> I want to understand why python use indentation to denote block of
> code. What are the advantages of it?

See the FAQ:
http://www.python.org/doc/faq/general/#why-does-python-use-indentation-for-grouping-of-statements

> Is there a style in python to
> denote a block of code the same as that of C++ (with '{}')?

No.

> One disadvantage of using indentation to denote a block of code is
> that the runtime to automatically indent a python code would be about
> a few times more than the runtime to automatically indent a C++ code
> of the same length (both are in vim).

In fact it's pretty much impossible to automatically indent Python
code that has had its indentation removed; it's impossible to know for
sure where the dedents should occur.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list