Skip to content

[3.14] gh-137668: Document that ord() supports also bytes and bytearray (GH-137669) #137703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1562,13 +1562,19 @@ 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
representing the Unicode code point of that character. For example,
Return the ordinal value of a character.

If the argument is a one-character string, return 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 its single byte value.
For example, ``ord(b'a')`` returns the integer ``97``.


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

Expand Down
12 changes: 9 additions & 3 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2119,15 +2119,21 @@ 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 ordinal value of a character.

If the argument is a one-character string, return the Unicode code
point of that character.

If the argument is a bytes or bytearray object of length 1, return its
single byte value.
[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=98d38480432e1177]*/
{
long ord;
Py_ssize_t size;
Expand Down
12 changes: 9 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