liveBook · Manning

Whitespace character

As explained in The Quick Python Book, Fourth Edition

Whitespace is non-printing character spacing, such as spaces, tabs, and line breaks, that can separate or structure source code.

Whitespace characters are invisible spacing elements such as spaces, tabs, and line breaks. They can improve readability, separate fields, or determine source-code structure. section 4.1 section 21.4.3

Whitespace matters in several practical ways:

  • Python uses indentation, rather than braces, to define the bodies of loops and conditional clauses. section 4.1
  • Extra spaces at line beginnings or around fields can interfere with loading and processing data. section 21.4.3
  • Tabs and spaces can be visually similar while producing troublesome or inconsistent input. section 21.4.3
  • Additional whitespace can make code easier to read, although formatting choices should remain purposeful. section 5.9.3

Indentation as structure

In Python, the indented statements belong to the while loop: n = 9 r = 1 while n > 0: r = r * n n = n - 1 Removing that indentation changes which statements are inside the loop. In contrast, C uses braces for structure, so indentation alone can be rearranged without changing execution. section 4.1

# This is Python code.
n = 9
r = 1
while n > 0:
    r = r * n         #1
    n = n - 1         #2

Inspect a compact Python example where whitespace and indentation delimit the loop body. section 4.1

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Explains indentation and cleaning pitfalls with concrete comparisons, but stops short of specifying whitespace character encodings or parsing algorithms.
Examples
Demonstrates Python loop indentation, equivalent C brace styles, formatted AI-generated code, and whitespace around imported data fields.
What it assumes
Assumes general programming knowledge while introducing Python's indentation-based block structure and practical whitespace hazards.
What you can do after
Diagnose whitespace-related structure and data-loading problems by inspecting indentation, field boundaries, tabs, and spaces.
How it connects
Connects whitespace with indentation, block structure, data cleaning, parsing, readability, tabs, spaces, and braces.

Also explained in

Compare how 3 books explain whitespace character →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.