Indentation
Wondering why when we as a kids missed the indentation in the writing class we lost marks?
what is this white space? why is it important?
assume writing different stories in a paper without dividing them into paragraph how can you ever understand that you already finished a story and starting a new one? indentation is the red flag that tells you STOP you are now entering a new clan.
Indentation in Python refers the space at the begging of the statement. The statements with the same indentation belong to the same group called a suite.
Since we are so cool that the interpreter imitates our actions, we understand that these lines are related to each other due to the indentation. Without indentation, Python does not know which statement to execute next or which statement belongs to which block.
Not understanding how indentation works will drive you to see the very famous error
INDENTATIONERROR
If python was not your first stop when learning to code you probably used {} to define your scopes like most of languages like C++ or java.
If you are the type of person who use nested for loops where your "On" is On^5 your code will simply be indented further to the right.
IF you understood nothing don't worry the code is coming to rescue you.
statues="Coding is fun"
if statues == "Coding is fun":
print('passed')
else:
print('retake the course')
print('Whoohoo ! Lets understand indentation ^_^')
As you see the first print command is indented to the right which makes it belong to the if statues (if the condition is true) execute this command
if not, print the second line.
while the third print command is not indented to the right so it doesn't belong to the else condition so it was printed.
Comments