The use of :

Nick Coghlan ncoghlan at email.com
Sat Nov 27 07:58:56 EST 2004


Dave Anderson wrote:
> this is answered in the python faq:
> 
> http://www.python.org/doc/faq/general.html#why-are-colons-required-for-the-if-while-def-class-statements 
> 
> 
>> The colon is required primarily to enhance readability

It also allows 'suiteless' versions of some statements:

   if x > 0: print "Greater that 0"
   while x > 0: x -= 1
   def f(): pass
   class c(object): pass
   for x in range(4): print x


Actually using that feature outside sample code is generally bad karma, though ;)

Cheers,
Nick.





More information about the Python-list mailing list