mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
GH-130153: Reword the wildcard matching part of the tutorial (GH-129954)
This commit is contained in:
parent
ba05a4ebcb
commit
1b5db5adfe
1 changed files with 3 additions and 2 deletions
|
|
@ -289,7 +289,8 @@ similar to a switch statement in C, Java or JavaScript (and many
|
|||
other languages), but it's more similar to pattern matching in
|
||||
languages like Rust or Haskell. Only the first pattern that matches
|
||||
gets executed and it can also extract components (sequence elements
|
||||
or object attributes) from the value into variables.
|
||||
or object attributes) from the value into variables. If no case matches,
|
||||
none of the branches is executed.
|
||||
|
||||
The simplest form compares a subject value against one or more literals::
|
||||
|
||||
|
|
@ -305,7 +306,7 @@ The simplest form compares a subject value against one or more literals::
|
|||
return "Something's wrong with the internet"
|
||||
|
||||
Note the last block: the "variable name" ``_`` acts as a *wildcard* and
|
||||
never fails to match. If no case matches, none of the branches is executed.
|
||||
never fails to match.
|
||||
|
||||
You can combine several literals in a single pattern using ``|`` ("or")::
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue