mirror of
https://github.com/python/cpython.git
synced 2025-10-20 16:33:53 +00:00
gh-137668: Document that ord() supports also bytes and bytearray (GH-137669)
This commit is contained in:
parent
639df39bf0
commit
35759fe2fa
3 changed files with 27 additions and 9 deletions
|
@ -1562,13 +1562,19 @@ are always available. They are listed here in alphabetical order.
|
||||||
.. versionchanged:: 3.11
|
.. versionchanged:: 3.11
|
||||||
The ``'U'`` mode has been removed.
|
The ``'U'`` mode has been removed.
|
||||||
|
|
||||||
.. function:: ord(c)
|
.. function:: ord(character, /)
|
||||||
|
|
||||||
Given a string representing one Unicode character, return an integer
|
Return the ordinal value of a character.
|
||||||
representing the Unicode code point of that character. For example,
|
|
||||||
|
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)
|
``ord('a')`` returns the integer ``97`` and ``ord('€')`` (Euro sign)
|
||||||
returns ``8364``. This is the inverse of :func:`chr`.
|
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)
|
.. function:: pow(base, exp, mod=None)
|
||||||
|
|
||||||
|
|
|
@ -2118,15 +2118,21 @@ builtin_oct(PyObject *module, PyObject *number)
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
ord as builtin_ord
|
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]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
builtin_ord(PyObject *module, PyObject *c)
|
builtin_ord(PyObject *module, PyObject *c)
|
||||||
/*[clinic end generated code: output=4fa5e87a323bae71 input=3064e5d6203ad012]*/
|
/*[clinic end generated code: output=4fa5e87a323bae71 input=98d38480432e1177]*/
|
||||||
{
|
{
|
||||||
long ord;
|
long ord;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
|
|
12
Python/clinic/bltinmodule.c.h
generated
12
Python/clinic/bltinmodule.c.h
generated
|
@ -831,10 +831,16 @@ PyDoc_STRVAR(builtin_oct__doc__,
|
||||||
{"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
|
{"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
|
||||||
|
|
||||||
PyDoc_STRVAR(builtin_ord__doc__,
|
PyDoc_STRVAR(builtin_ord__doc__,
|
||||||
"ord($module, c, /)\n"
|
"ord($module, character, /)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Return the Unicode code point for a one-character string.");
|
"Return the ordinal value of a character.\n"
|
||||||
|
"\n"
|
||||||
|
"If the argument is a one-character string, return the Unicode code\n"
|
||||||
|
"point of that character.\n"
|
||||||
|
"\n"
|
||||||
|
"If the argument is a bytes or bytearray object of length 1, return its\n"
|
||||||
|
"single byte value.");
|
||||||
|
|
||||||
#define BUILTIN_ORD_METHODDEF \
|
#define BUILTIN_ORD_METHODDEF \
|
||||||
{"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
|
{"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
|
||||||
|
@ -1268,4 +1274,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=e7a5d0851d7f2cfb input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=cd5f80e3dc3082d5 input=a9049054013a1b77]*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue