Skip to content

Commit

Permalink
📝 Extend documentation of the string type
Browse files Browse the repository at this point in the history
  • Loading branch information
veit committed Sep 1, 2024
1 parent 8103b2e commit e5c4048
Show file tree
Hide file tree
Showing 2 changed files with 377 additions and 46 deletions.
18 changes: 15 additions & 3 deletions docs/appendix/checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,25 @@ Checks
>>> x[:9] == ".. note::"
True
* Suppose you have a string with punctuation marks, inverted commas and line
* Suppose you have a string with exclamation marks, quotation marks and line
breaks. How can these be removed from the string?

.. code-block:: pycon
>>> hipy = ["‘Hello", "Pythonistas!’\n"]
>>> string.strip("‘’!\n")
>>> hipy = "„Hello Pythonistas!“\n"
>>> hipy.strip("„“!\n")
'Hello Pythonistas'
* How can you change all spaces and punctuation marks from a string to a hyphen
(``-``)?

.. code-block:: pycon
>>> from string import punctuation, whitespace
>>> chars = punctuation + whitespace
>>> subs = str.maketrans(chars, len(chars) * "-")
>>> hipy = "Hello Pythonistas!\n"
>>> hipy.translate(subs)
'Hello-Pythonistas--'
* Which regular expression would you use to find strings that represent the
numbers between -3 and +3?
Expand Down
Loading

0 comments on commit e5c4048

Please sign in to comment.