2.3.11

Whitespace

Test yourself

Whitespace

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

Illustrative background for IndentationIllustrative background for Indentation ?? "content

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.
Illustrative background for Blank linesIllustrative background for Blank lines ?? "content

Blank lines

  • Sometimes blank lines can be used to make code more readable.
  • In Python, the guidelines are:
    • Subroutines should be separated by a blank line.
    • 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.

Jump to other topics

1Computational Thinking & Algorithms

2Programming

3Hardware & Software

4Data

5The Internet

6Online Safety & Security

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson