September 2026
1051 pages
35h 4m
English
The structural pattern matching of Python provides wide-ranging options to define patterns. We’ll highlight several of these in this section.
The simplest case of a pattern is to explicitly write the matching value as a literal, as we did in the introductory example for strings. The following literals are allowed:
String literals
Literals for signed and unsigned numbers
None, True, and False
In addition, it’s possible not to specify values explicitly by their literal, but to use a reference to the desired value instead. To avoid ambiguities with the capture patterns we’ll describe later (Section 25.2.6), there is a restriction here that references must be ...
Read now
Unlock full access