Compare source code

Neil Cerutti neilc at norwich.edu
Thu Nov 4 10:15:25 EDT 2010


On 2010-11-05, Ethan Furman <ethan at stoneleaf.us> wrote:
> Grant Edwards wrote:
>> On 2010-11-04, Emile van Sebille <emile at fenx.com> wrote:
>>> On 11/3/2010 4:09 PM Seebs said...
>>>> What's the token that marks the end of a block,
>>>> corresponding to the colon used to introduce it?
>>>
>>> My thoughts tend more towards 'can we get Guido to eliminate
>>> the colon requirements' -- The indent level of the next line
>>> ought to suffice.
>> 
>> But without the colon, how are people who write programming
>> editors going to know when to increase the indentation level
>> as I enter code?
>
> Hopefully by the keywords used to introduce the block: if,
> elif, else, for, while, with, etc. etc.  It is not legal to
> start a new indented block just by appending a colon to the
> previous line.

The handsome ':' terminator of if/elif/if statements allows us to
omit a newline, conserving vertical space. This improves the
readability of certain constructs.

if x: print(x)
elif y: print(y)
else: print()

versus

if x
    print(x)
elif y
    print(y)
else
    print()

Beauty-is-in-the-eye-of-the-BDFLly-yours,

-- 
Neil Cerutti



More information about the Python-list mailing list