How do you know when to add colon or indent in a program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

How do you know when to add colon or indent in a program?

30th Jun 2020, 9:10 PM
Chimamanda
Chimamanda - avatar
2 Answers
+ 5
(1). You can try remembering the statements, that require it. Statements followed by colons are statements, that require a code block. A code block "always" requires indenting. (2). You can think logically about what kind of statements would need a code block. Think about if statement, reading: if 5 > 2 would not make any sense, if 5 > 2, then what? This makes more sense: if 5 > 2: print("5 is greater than 2") because something is told to happen if 5 > 2.
30th Jun 2020, 9:34 PM
Seb TheS
Seb TheS - avatar