Whitespace

Computer Science: KS3, topic 2.3.11

Whitespace

Whitespace is key to Python, since it is used to separate blocks of code.

Indentation

Indentation

  • Indentation is necessary in Python to control program flow.
  • Even in languages where it is optional, it is best practice since it makes code more readable.
Blank lines

Blank lines

  • Sometimes blank lines can be used to make code more readable.
  • In Python, the guidelines are:
  • Subroutines should be separated by two blank lines.
  • Blank lines can be used sparingly in subroutines to show sections of the subroutine.
  • Other lines of code should not have blank space around them.

Test yourself on Whitespace

  • Why is it always a good idea to use indentation?

  • Can blank lines be used within subroutines?

Practise this topic for free