0
Why there should space at the start of line in the statements within if ?
What do we mean by delimiting of code....? What type of error would it show by not leaving space at the beginning of the line within the statements?
2 Antworten
0
In python, the spaces after the conditional statements (if/elif/else) and others, tell python to execute this 'block of code' when this condition is met (or list of instructions). You cant leave it blank because then it is as if you're saying to python (When this condition is met, do nothing). Indentation in python is important because it tells python where blocks of code belong.
Imagine _ (underscore) as a space.
1
1
1
1
_2
_2
_2
1
1
_2
_2
__3
__3
Python executes the 1's first, until it comes to lets say an if statement (2), and if the if statement is True, then the code block (_2) executes. After all the 2's are finished, then it continues back to the 1's down the lines of code. The same process repeats. This also applies to blocks of code under more blocks of code.
Adding spaces where there shouldn't be any, gives an indentation error. Which python will kindly point out.
0
like in c language we use curly braces for intendeding. In Python we use space at the starting of if statement