An interesting beginner question: why we need colon at all in the python language?
Anthony Kong
anthony.hw.kong at gmail.com
Mon Jul 11 11:10:44 EDT 2011
Sorry, typo in my original question. I do mean 'colon'. It should have read
*If Python use indentation to denote scope, why it still needs colon at the
end of function declaration and for/while/if loop?*
Thanks
On Tue, Jul 12, 2011 at 12:36 AM, Dave Angel <davea at ieee.org> wrote:
> On 01/-10/-28163 02:59 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!
>>
>> Is there any other reasons for use of semi-colon in python?
>>
>>
>> Cheers
>>
>> You're confusing the colon with the semi-colon. If you want two
> statements on the same line, you use a semi-colon.
>
> The character you're asking about is the colon. It goes at the end of an
> if, else, for, with, while statement. I doubt it's absolutely essential,
> but it helps readability, since a conditional expression might span multiple
> lines.
> if someexpression ==
> someotherexpression:
> body_of_the_conditional
>
> DaveA
>
>
--
/*--*/
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110712/204cfcd7/attachment.html>
More information about the Python-list
mailing list