Python: where is your colon?


I’ve just got back from the most excellent PyCon UK 2007.

One trivial observation that occurred to me is that I seem to be the only Python programmer that puts a space before the colon. Like this:

def double(x) : 
  return x * 2

I think the reason that I do that is that I think of the colon as being equivalent to the opening brace, «{», in a language like C, and of course I would never omit the space between the «)» and the «{» in «if(x) {».

2 Responses to “Python: where is your colon?”

  1. Paul Says:

    PEP 8 says not to.

  2. drj11 Says:

    Yeah, but PEP8 also says crazy stuff like “use a 4 space indent” and don’t write “hypot2 = x*x + y*y”. I can’t really complain though, it’s such a good example of coding style on the whole.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: