Why do we use colons (:) after an 'if' statement?

Asked by blessing007 · 2 weeks ago

1 Answer

19
amorebise · 2 weeks ago Top Answer

The colon is like a gate. It tells Python: "Okay, the condition is finished, now look at the indented lines below to see what to do."

If you forget the colon, Python won't know where the decision ends and the action begins. It's just a piece of punctuation you'll eventually type without even thinking.

Log in to add a comment.