Building blocks of Python: Indentation and statement

4. Indentations


  • Unlike other programming languages, Python uses indentations to define a block of code
  • A code block (body of a function, loop etc) starts with indentation and ends with the first unindented line.
  • The amount of indentation is up to the user, but it must be consistent
  • Generally four whitespaces are used for indentation and is preferred over tabs
  • Leading whitespaces (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements.
  • Indentation is a good way to keep the code readable







5. Python Statement

  • Instructions that a Python interpreter can execute are called statements.
  • For example, a = 1 is an assignment statement.
  • if statement, for statement, while statement etc. are other kinds of statements which will be discussed later.







Comments