[python-advocacy] example code

Aahz aahz at pythoncraft.com
Thu Nov 12 18:20:21 CET 2009


On Thu, Nov 12, 2009, Ray Allen wrote:
>
> # Create  list
> python = ["Easy to read",
> "Fast to code",
> "Quick to learn",
> "Modular and object oriented"]

AFAIK, almost everyone indents multi-line expressions.  There are several
ways to do it, this is my preferred version:

python = [
    "Easy to read",
    "Fast to code",
    "Quick to learn",
    "Modular and object oriented",
    ]

The reason I prefer this is because it makes it easy to edit the list,
specifically including the trailing comma on the last element.  (E.g.
it's much easier to delete the first list element than when you put it
next to the opening bracket -- just delete the line.)  It's also easy to
read because the beginning and end of the list are highly visible.  I
prefer to indent only one level rather than matching up the beginning and
ending brackets because that gives more line length to the list contents.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke


More information about the Advocacy mailing list