Encapsulation, inheritance and polymorphism

Dave Angel d at davea.name
Tue Jul 17 07:23:13 EDT 2012


On 07/17/2012 07:01 AM, Lipska the Kat wrote:
> <SNIP>
>
> Anyway, I'm looking at Python as a rapid prototyping language.
> I have an idea and just want to get it down in basic outline code as
> quickly as possible before it departs my aging brain... I'm not used
> to using variables without declaring their type ... (well I used to do
> Visual Basic many years ago) It just seems so weird, and what's this
> obsession with 'correct' indentation of code ???
>

Welcome to comp.lang.python.  I hope you enjoy learning and using Python.

Indentation isn't just custom in Python.  It's part of the syntax. 
Other languages use braces, or keywords, to indicate scope, but Python
uses indentation.  Other than the occasional tab to confuse things, the
rules are pretty simple.

You must indent the body of a function, the scope of an if or else
clause, or other similar language pieces (class, try, except, ...)
Within such a scope, you cannot change indentation, except of course for
a nested scope.
At the end of such scope you must outdent to the previous state.

The convention is to use 4 spaces per indentation, but the language will
accept any amount, as long as it's consistent within any single scope. 
And although mixing tabs and space worked in Python 2.x, sort of, it's
disallowed in Python 3.

An expression may span multiple lines, but only if it's unambiguous to
the compiler (eg. a pending left paren with no matching right paren
yet).  In that case. indentation of the subsequent lines is unrestricted.

HTH

-- 

DaveA




More information about the Python-list mailing list