Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d4dd3e

Browse files
committed
Issue 7828: Fixed chr() and ord() documentation for wide characters
1 parent de60918 commit 5d4dd3e

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

Doc/library/functions.rst

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ are always available. They are listed here in alphabetical order.
105105

106106
.. function:: chr(i)
107107

108-
Return the string of one character whose Unicode codepoint is the integer
108+
Return the string representing a character whose Unicode codepoint is the integer
109109
*i*. For example, ``chr(97)`` returns the string ``'a'``. This is the
110-
inverse of :func:`ord`. The valid range for the argument depends how Python
111-
was configured -- it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF].
112-
:exc:`ValueError` will be raised if *i* is outside that range.
110+
inverse of :func:`ord`. The valid range for the argument is from 0 through
111+
1,114,111 (0x10FFFF in base 16). :exc:`ValueError` will be raised if *i* is
112+
outside that range.
113+
114+
Note that on narrow Unicode builds, the result is a string of
115+
length two for *i* greater than 65,535 (0xFFFF in hexadecimal).
116+
113117

114118

115119
.. function:: classmethod(function)
@@ -822,14 +826,14 @@ are always available. They are listed here in alphabetical order.
822826
.. XXX works for bytes too, but should it?
823827
.. function:: ord(c)
824828

825-
Given a string of length one, return an integer representing the Unicode code
826-
point of the character. For example, ``ord('a')`` returns the integer ``97``
829+
Given a string representing one Uncicode character, return an integer
830+
representing the Unicode code
831+
point of that character. For example, ``ord('a')`` returns the integer ``97``
827832
and ``ord('\u2020')`` returns ``8224``. This is the inverse of :func:`chr`.
828833

829-
If the argument length is not one, a :exc:`TypeError` will be raised. (If
830-
Python was built with UCS2 Unicode, then the character's code point must be
831-
in the range [0..65535] inclusive; otherwise the string length is two!)
832-
834+
On wide Unicode builds, if the argument length is not one, a
835+
:exc:`TypeError` will be raised. On narrow Unicode builds, strings
836+
of length two are accepted when they form a UTF-16 surrogate pair.
833837

834838
.. function:: pow(x, y[, z])
835839

0 commit comments

Comments
 (0)