Skip to content

Commit 558324e

Browse files
miss-islingtonserhiy-storchaka
authored andcommitted
[3.14] pythongh-137668: Document that ord() supports also bytes and bytearray (pythonGH-137669) (python#137703)
Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent aed4fb2 commit 558324e

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

Doc/library/functions.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,13 +1559,19 @@ are always available. They are listed here in alphabetical order.
15591559
.. versionchanged:: 3.11
15601560
The ``'U'`` mode has been removed.
15611561

1562-
.. function:: ord(c)
1562+
.. function:: ord(character, /)
15631563

1564-
Given a string representing one Unicode character, return an integer
1565-
representing the Unicode code point of that character. For example,
1564+
Return the ordinal value of a character.
1565+
1566+
If the argument is a one-character string, return the Unicode code point
1567+
of that character. For example,
15661568
``ord('a')`` returns the integer ``97`` and ``ord('€')`` (Euro sign)
15671569
returns ``8364``. This is the inverse of :func:`chr`.
15681570

1571+
If the argument is a :class:`bytes` or :class:`bytearray` object of
1572+
length 1, return its single byte value.
1573+
For example, ``ord(b'a')`` returns the integer ``97``.
1574+
15691575

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

Python/bltinmodule.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,15 +2119,21 @@ builtin_oct(PyObject *module, PyObject *number)
21192119
/*[clinic input]
21202120
ord as builtin_ord
21212121
2122-
c: object
2122+
character as c: object
21232123
/
21242124
2125-
Return the Unicode code point for a one-character string.
2125+
Return the ordinal value of a character.
2126+
2127+
If the argument is a one-character string, return the Unicode code
2128+
point of that character.
2129+
2130+
If the argument is a bytes or bytearray object of length 1, return its
2131+
single byte value.
21262132
[clinic start generated code]*/
21272133

21282134
static PyObject *
21292135
builtin_ord(PyObject *module, PyObject *c)
2130-
/*[clinic end generated code: output=4fa5e87a323bae71 input=3064e5d6203ad012]*/
2136+
/*[clinic end generated code: output=4fa5e87a323bae71 input=98d38480432e1177]*/
21312137
{
21322138
long ord;
21332139
Py_ssize_t size;

Python/clinic/bltinmodule.c.h

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)