An interesting beginner question: why we need colon at all in the python language?

Sébastien Volle sebastien.volle at gmail.com
Mon Jul 11 16:50:20 CEST 2011


Could it have been made optional, like the trailing comma in list
declaration?

--
Seb

2011/7/11 Anthony Kong <anthony.hw.kong at gmail.com>

> Awesome! Thanks for blog post link
>
> Cheers
>
>
> On Tue, Jul 12, 2011 at 12:16 AM, Thomas Jollans <t at jollybox.de> wrote:
>
>> On 07/11/2011 03:51 PM, Anthony Kong wrote:
>> > Hi, all,
>> >
>> > Lately I am giving some presentations to my colleagues about the python
>> > language. A new internal project is coming up which will require the use
>> > of python.
>> >
>> > One of my colleague asked an interesting:
>> >
>> > /If Python use indentation to denote scope, why it still needs
>> > semi-colon at the end of function declaration and for/while/if loop?/
>> >
>> > My immediate response is: it allows us to fit statements into one line.
>> > e.g. if a == 1: print a
>> >
>> > However I do not find it to be a particularly strong argument. I think
>> > PEP8 does not recommend this kind of coding style anyway, so one-liner
>> > should not be used in the first place!
>>
>> Basically, it looks better, and is more readable. A colon, in English
>> like in Python, means that something follows that is related to what was
>> before the colon. So the colon makes it abundantly clear to the human
>> reader that a block follows, and that that block is to be considered in
>> relation to what was just said, before the colon.
>>
>> Coincidentally, Guido wrote this blog post just last week, without which
>> I'd be just as much at a loss as you:
>>
>>
>> http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> /*--*/
> Don’t EVER make the mistake that you can design something better than what
> you get from ruthless massively parallel trial-and-error with a feedback
> cycle. That’s giving your intelligence _much_ too much credit.
>
> - Linus Torvalds
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110711/1a714640/attachment.html>


More information about the Python-list mailing list