0

Python is not only a case sensitive Language. Also it cares about indentation of a program. While programmers learning Python without using braces to indicate blocks of code for class and function definitions or flow control, programmers faces caveats of program or Indentation error in it. 

For example consider the simple example. It will give you basic understand of the indentation.

if True:                                                       
    print " Validation success ";                    
    print "Continue to proceed more steps "; 
else:                                                           
    print " Validation failure ";                      
    print " Try again ";                                  

In the above example after the if condition without using braces, it is possible to execute more that one line of commands by maintaining indentation of the each lines. This indentation helps to varies the different blocks while executing in the program.

Check the screenshot of source file and its corresponding output while indentation varies on the program.




Correct Source Screenshot :







Correct Source Output Screenshot :





If the indentation changes in order it will provide indentation error. We made indentation space in different order. It gives the inderntation error show below.



Indentation Changed Source Screenshot : 




see there is in True block, first print statement and second print statement indentation order.






Indentation Changed Source Output Screenshot :




I think you will clear understand about Lines and Indentation in Python Program.

If you have any queries post below in comment box. We will help you.

Thank you.



Post a Comment

 
Top