Indentation

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 functionloop 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.

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.

a_var=1
print  ‘Heading’.
If  a_var==1:
     print ‘Value is One’
else:
     print ‘Value is Not One’

Result



No comments:

Post a Comment