Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1562,13 +1562,18 @@ are always available. They are listed here in alphabetical order.
.. versionchanged:: 3.11
The ``'U'`` mode has been removed.

.. function:: ord(c)
.. function:: ord(character, /)

Given a string representing one Unicode character, return an integer
The argument must be a one-character string or a :class:`bytes` or
Copy link
Member

Choose a reason for hiding this comment

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

These lines are now duplicated; what about:

character must be of length 1.

If it is a :class:str return …

If it is a :class:bytes or :class:bytearray object, return …

Copy link
Member

Choose a reason for hiding this comment

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

Alternate suggestion: Give the length restriction once in the initial summary sentence. "Return an integer representing a character, a length 1 str, bytes, or bytearray. If a string, return the unicode ... inverse ... char. For bytes or bytearray, return the integer itself."

Copy link
Member Author

Choose a reason for hiding this comment

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

What if remove any concrete types from the initial line, and only mentioned them in type-specific descriptions?

:class:`bytearray` object of length 1.
If it is a one-character string, return an integer
representing the Unicode code point of that character. For example,
``ord('a')`` returns the integer ``97`` and ``ord('€')`` (Euro sign)
returns ``8364``. This is the inverse of :func:`chr`.

If the argument is a :class:`!bytes` or :class:`!bytearray` object of
length 1, return an integer value of its element.


.. function:: pow(base, exp, mod=None)

Expand Down
7 changes: 5 additions & 2 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2118,15 +2118,18 @@ builtin_oct(PyObject *module, PyObject *number)
/*[clinic input]
ord as builtin_ord

c: object
character as c: object
/

Return the Unicode code point for a one-character string.

Return the value of the first byte for a bytes or bytearray object of
length 1.
[clinic start generated code]*/

static PyObject *
builtin_ord(PyObject *module, PyObject *c)
/*[clinic end generated code: output=4fa5e87a323bae71 input=3064e5d6203ad012]*/
/*[clinic end generated code: output=4fa5e87a323bae71 input=99e491d094680598]*/
{
long ord;
Py_ssize_t size;
Expand Down
9 changes: 6 additions & 3 deletions Python/clinic/bltinmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading