Skip to content

Commit a4d2125

Browse files
committed
In Doc/library/re.rst rename variables from match to m
`match` has been a soft keyword since version 3.10, so examples ought to not use it as the name of a variable. https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords The new name, `m`, is used for match objects in other examples in re.rst.
1 parent 77dd973 commit a4d2125

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Doc/library/re.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,8 @@ Since :meth:`~Pattern.match` and :meth:`~Pattern.search` return ``None``
14831483
when there is no match, you can test whether there was a match with a simple
14841484
``if`` statement::
14851485

1486-
if match := re.search(pattern, string):
1487-
process(match)
1486+
if m := re.search(pattern, string):
1487+
process(m)
14881488

14891489
.. class:: Match
14901490

@@ -1707,10 +1707,10 @@ Checking for a pair
17071707
In this example, we'll use the following helper function to display match
17081708
objects a little more gracefully::
17091709

1710-
def displaymatch(match):
1711-
if match is None:
1710+
def displaymatch(m):
1711+
if m is None:
17121712
return None
1713-
return '<Match: %r, groups=%r>' % (match.group(), match.groups())
1713+
return '<Match: %r, groups=%r>' % (m.group(), m.groups())
17141714

17151715
Suppose you are writing a poker program where a player's hand is represented as
17161716
a 5-character string with each character representing a card, "a" for ace, "k"

0 commit comments

Comments
 (0)