Posts

Image
  What is Indentation? Indentation in Python refers to the use of whitespace (spaces or tabs) to define the structure and hierarchy of the code. Unlike many programming languages that use curly braces {} or other delimiters to group statements, Python uses indentation to indicate which statements are part of a block of code. This indentation is crucial for defining code blocks such as loops, conditionals, functions, and classes. For example, consider the following code.    All statements on the same level of indentation (same number of whitespaces preceding them) belong to a single block. Hence, statements on lines 1, 2, and 7 belong to a single block, and the block has the zero or lowest level of indentation, as shown in the picture above. Statements 3 and 5 are indented by one step, forming a new block at the first level of indentation. Statements 4 and 6 are similarly indented two steps, creating a new block at the second level of indentation.   Statements 3 and 5...