Skip to content
Prev Previous commit
Next Next commit
Add other methods of string formatting
  • Loading branch information
csabella committed Oct 21, 2017
commit b577580bf3ab2e111d4e370bb3314850dfabe562
166 changes: 85 additions & 81 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1384,87 +1384,91 @@ The following table summarizes the text and binary sequence types methods by
category.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this paragraph necessary? It seems obvious just given the section and table headings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Martin. You're right. I wasn't quite sure where to place this overall and thought there would probably be suggestions, so I kept it vague. There wasn't a section that combined both text and binary sequence types before and I didn't know if people would like having str and bytes (and bytearray) types all in one table or if there should be a separate table for each one under the existing sections.



+--------------------------+----------------------------------------+---------------------------------------------+
| Category | :class:`str` methods |:class:`bytes` and :class:`bytearray` methods|
+==========================+========================================+=============================================+
| Formatting | :meth:`str.format` | |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.format_map` | |
+--------------------------+-------------------+--------------------+----------------------+----------------------+
| Searching and Replacing | :meth:`str.find` | :meth:`str.rfind` | :meth:`bytes.find` | :meth:`bytes.rfind` |
+--------------------------+-------------------+--------------------+----------------------+----------------------+
| | :meth:`str.index` | :meth:`str.rindex` | :meth:`bytes.index` | :meth:`bytes.rindex` |
| +-------------------+--------------------+----------------------+----------------------+
| | :meth:`str.startswith` | :meth:`bytes.startswith` |
| +-------------------+--------------------+----------------------+----------------------+
| | :meth:`str.endswith` | :meth:`bytes.endswith` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.count` | :meth:`bytes.count` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.replace` | :meth:`bytes.replace` |
+--------------------------+-------------------+--------------------+----------------------+----------------------+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
+--------------------------+-------------------+--------------------+----------------------+----------------------+
| | :meth:`str.splitlines` | :meth:`bytes.splitlines` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.partition` | :meth:`bytes.partition` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.rpartition` | :meth:`bytes.rpartition` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.join` | :meth:`bytes.join` |
+--------------------------+----------------------------------------+---------------------------------------------+
| String Classification | :meth:`str.isalpha` | :meth:`bytes.isalpha` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isdecimal` | |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isdigit` | :meth:`bytes.isdigit` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isnumeric` | |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isalnum` | :meth:`bytes.isalnum` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isidentifier` | |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.islower` | :meth:`bytes.islower` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isupper` | :meth:`bytes.isupper` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.istitle` | :meth:`bytes.istitle` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isspace` | :meth:`bytes.isspace` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.isprintable` | |
+--------------------------+----------------------------------------+---------------------------------------------+
| Case Manipulation | :meth:`str.lower` | :meth:`bytes.lower` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.upper` | :meth:`bytes.upper` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.casefold` | |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.capitalize` | :meth:`bytes.capitalize` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.title` | :meth:`bytes.title` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.swapcase` | :meth:`bytes.swapcase` |
+--------------------------+-------------------+--------------------+----------------------+----------------------+
| Padding and Stripping | :meth:`str.ljust` | :meth:`str.rjust` | :meth:`bytes.ljust` | :meth:`bytes.rjust` |
| +-------------------+--------------------+----------------------+----------------------+
| | :meth:`str.center` | :meth:`bytes.center` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.expandtabs` | :meth:`bytes.expandtabs` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.strip` | :meth:`bytes.strip` |
| +-------------------+--------------------+----------------------+----------------------+
| | :meth:`str.lstrip`| :meth:`str.rstrip` | :meth:`bytes.lstrip` | :meth:`bytes.rstrip` |
+--------------------------+-------------------+--------------------+----------------------+----------------------+
| Translation and Encoding | :meth:`str.translate` | :meth:`bytes.translate` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.maketrans` | :meth:`bytes.maketrans` |
| +----------------------------------------+---------------------------------------------+
| | :meth:`str.encode` | |
| +----------------------------------------+---------------------------------------------+
| | | :meth:`bytes.decode` |
+--------------------------+----------------------------------------+---------------------------------------------+
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Category | :class:`str` methods | :class:`bytes` and :class:`bytearray` methods |
+==========================+===========================================+===================================================+
| Formatting | :meth:`str.format` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.format_map` | |
| +-------------------------------------------+---------------------------------------------------+
| | :ref:`f-strings` | |
| +-------------------------------------------+---------------------------------------------------+
| | :ref:`old-string-formatting` | :ref:`bytes-formatting` |
+--------------------------+------------------+------------------------+--------------------+------------------------------+
| Searching and Replacing | :meth:`str.find` | :meth:`str.rfind` | :meth:`bytes.find` | :meth:`bytes.rfind` |
+--------------------------+------------------+------------------------+--------------------+------------------------------+
| | :meth:`str.index`| :meth:`str.rindex` | :meth:`bytes.index`| :meth:`bytes.rindex` |
| +------------------+------------------------+--------------------+------------------------------+
| | :meth:`str.startswith` | :meth:`bytes.startswith` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.endswith` | :meth:`bytes.endswith` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.count` | :meth:`bytes.count` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.replace` | :meth:`bytes.replace` |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
+--------------------------+-------------------------------------------+---------------------------------------------------+

@encukou encukou Dec 19, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The r/l pairs (split/rsplit, ljust/rjust, lstrip/rstrip) need +s to render as table cells:

Suggested change
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
+--------------------------+-------------------------------------------+---------------------------------------------------+
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+

| | :meth:`str.splitlines` | :meth:`bytes.splitlines` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.partition` | :meth:`bytes.partition` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.rpartition` | :meth:`bytes.rpartition` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.join` | :meth:`bytes.join` |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| String Classification | :meth:`str.isalpha` | :meth:`bytes.isalpha` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isdecimal` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isdigit` | :meth:`bytes.isdigit` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isnumeric` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isalnum` | :meth:`bytes.isalnum` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isidentifier` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.islower` | :meth:`bytes.islower` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isupper` | :meth:`bytes.isupper` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.istitle` | :meth:`bytes.istitle` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isspace` | :meth:`bytes.isspace` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isprintable` | |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Case Manipulation | :meth:`str.lower` | :meth:`bytes.lower` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.upper` | :meth:`bytes.upper` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.casefold` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.capitalize` | :meth:`bytes.capitalize` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.title` | :meth:`bytes.title` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.swapcase` | :meth:`bytes.swapcase` |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Padding and Stripping | :meth:`str.ljust` | :meth:`str.rjust` | :meth:`bytes.ljust` | :meth:`bytes.rjust` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.center` | :meth:`bytes.center` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.expandtabs` | :meth:`bytes.expandtabs` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.strip` | :meth:`bytes.strip` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.lstrip` | :meth:`str.rstrip` | :meth:`bytes.lstrip` | :meth:`bytes.rstrip` |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Translation and Encoding | :meth:`str.translate` | :meth:`bytes.translate` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.maketrans` | :meth:`bytes.maketrans` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.encode` | |
| +-------------------------------------------+---------------------------------------------------+
| | | :meth:`bytes.decode` |
+--------------------------+-------------------------------------------+---------------------------------------------------+

.. _textseq:

Expand Down