+ 4
How do you know when to add colon or indent in a program?
2 Réponses
+ 4
conditions require colons and indentions are for those lines inside conditions... Amanda Unachukwu
here are some additional threads which may be helpful
https://www.sololearn.com/discuss/2328899/?ref=app
https://www.sololearn.com/discuss/295269/?ref=app
https://www.sololearn.com/discuss/120135/?ref=app
https://www.sololearn.com/discuss/86700/?ref=app
https://www.sololearn.com/discuss/96081/?ref=app
https://www.sololearn.com/discuss/56564/?ref=app
https://www.sololearn.com/discuss/88918/?ref=app
https://www.sololearn.com/discuss/1623776/?ref=app
https://www.sololearn.com/discuss/2274298/?ref=app
https://www.sololearn.com/discuss/268700/?ref=app
https://www.sololearn.com/discuss/1914788/?ref=app
https://www.sololearn.com/discuss/1093005/?ref=app
https://www.sololearn.com/discuss/439192/?ref=app
+ 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.