Indentation.
- Python uses
indentation to define block of code , unlike other programming languages. Most
of the programming languages like C, C++, Java use braces { } to define a block
of code.
- A code block (body
of a function, loop etc.) starts
with indentation and ends with the first unindented line. It must be consistent
throughout that block, otherwise it will give indenting error or may give a
different result.
Example 1
This will result an indentation Error.
This will result an indentation Error.
a_var=1
print
‘Heading’.
If
a_var==1:
print ‘Value is One’
else:
print ‘Value is Not One’
Result
Example 2
Here Indentation is proper and It will not generate any Indentation Error.
Here Indentation is proper and It will not generate any Indentation Error.
a_var=1
print
‘Heading’.
If
a_var==1:
print ‘Value is One’
else:
print ‘Value is Not One’
Result
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7pODYs7k24VcbKAhbuXSFCUiMA5pLE_xmRS79l0imr5a5nQaEWrc5aZz7aIqgaxDrbYnm5oskOxeUgNWvPFG-FatUTDbHlepw8qi0CD567ub3RgDzMs25MlId2fWHy3EtVkDnecWe3fTP/s640/Indentation2.png)
No comments:
Post a Comment