Python Indentation

In python programming language code blocks are defined using indents. Multiple indents are used for nesting different or similar control structures. Normally in all programming languages curly parenthesis are used for defining body of control structure or function. In python we place an indent after control structure in new line for writing its code block. Indents is a sequence of blank spaces. Normally it consist of five or eight spaces. It depends on the operating system being used.

Meaning of indentation in python is creating child block of code. It is part of syntax and paly an important role while writing python script.

Use of indentation in python

There are some common and important uses of indentation in python scripting.
  • Write body of function.
  • Writing body of control structures
  • Writing TRUE or FLASE case statements of if statement.
  • To write body of iterative structures
  • Writing body of classes
  • Nesting Control Structures

How to correct indentation in python

There may be some irregular spaces in python script for writing block of codes. For correct indentation in python we just have to press Tab key from the keyboard. It will place an indent according to the operating system specifications.

Indentation in python with example

Every example having any control structure implementation is an example of indentation.

x = 10
if x < 100:
    print("Less Than 100")
else:
    print("Greater Then 100")

Here in this example we place single indent after if and else statement.

 
 
Comments
Login to TRACK of Comments.