Colon is used to increase readability,also help editors/IDE's to automatically indent the next line if the previous line ended with a colon.
Python FAQ
The History of Python
Python’s use of indentation comes directly from ABC,
but this idea didn’t originate with ABC--it had already been promoted by Donald Knuth and was a well-known concept of programming style.
(The occam programming language also used it.)
However, ABC’s authors did invent the use of the colon that separates the lead-in clause from the indented block.
After early user testing without the colon,
it was discovered that the meaning of the indentation was unclear to beginners being taught the first steps of programming.
The addition of the
colon
clarified it significantly: the
colon
somehow draws attention to what follows and ties the phrases before and after it together in just the right way.
GVR Wrote:Now the Dewar story, which is how I got the idea of the colon
,
as I wrote it down in a memoir of the ABC design rationale:
In 1978, in a design session in a mansion in Jabłonna (Poland),
Robert Dewar, Peter King, Jack Schwartz and Lambert were comparing various alternative proposed syntaxes for B,
by comparing (buggy) bubble sort implementations written down in each alternative.
Since they couldn't agree, Robert Dewar's wife was called from her room and asked for her opinion,
like a modern-day Paris asked to compare the beauty of Hera, Athena, and Aphrodite.
But after the first version was explained to her, she remarked: "You mean, in the line where it says: 'FOR i ... ',
that it has to be done for the lines that follow; not just for that line?!"
And here the scientists realized that the misunderstanding would have been avoided if there had been a
colon
at the end of that line.