Friday, March 2, 2018

Lines and Indentation in Python 3

Lines and Indentation in Python 3:

Python does not use braces({}) to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation, which is rigidly enforced.The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount. For example -

if True:
    print ("True")
else:
    print ("False")

 However, the following block generates an error -


If True:
   print ("Answer")
   print ("True")
else:
   print "(Answer")
   print ("False")

Thus, in Python all the continuous lines indented with the same number of spaces would form a block.