Indentation in Python

 Indentation in Python 

Indentation is a Whitespace at the beginning of a code line.
·         Python does not know which statement to execute next or belongs to which block.
·         Without proper indenting the Python generating Indentation Error and the code will not get
            compiled.
·         Indentation telling to Python interpreter that the group of statements belongs to a particular block
            of code.
·         A block is a group of statements for a specific purpose, In  C, C++, Java uses braces { } for this.
·         All statements with the same distance to the right belong to the same code block.
 Ex:-
>>>if 5 > 2:
            print("Five is greater than two!")
output:-
Five is greater than two!
 
Ex:-
>>>if 5 > 2:
   print("Five is greater than two!")
output:-:-
%Run a1.py
Traceback (most recent call last):
    if 5 > 2:
    ^
IndentationError: unexpected indent
==================================================== 


Post a Comment

0 Comments