Qu

chr

Builtin index · Collections & strings

result = chr(n), ord(s)

Input: n · Output: result

What it is

chr(n): n is a numeric Unicode code point — not a byte, so chr(9731) is a snowman, not an error. ord(s): s is a Str; a longer string is not an error, only its FIRST character is read, so ord("Abc") is 65. asc is a second name for ord.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = chr(n), ord(s)
n Str or stringnot documented yet
result Str or number
Returns a one-character Str from chr, and a number — the code point — from ord.

Examples

No documentation example calls this form yet. The Collections & strings chapter is where one belongs.

How it works

trim(s) / upper(s) / lower(s) — whitespace trim and unicode-aware case conversion, straight off str's own stdlib methods. chr(n) / ord(s) -- code point to character and back. chr is the escape hatch for every character that has no escape spelling: chr(27) for ESC, chr(176) for the degree sign, chr(0x2264) for a real "<=" glyph in an axis label. ord is its inverse and exists because a chr without one is half a feature -- you can build a byte but never inspect one. Unicode scalar values, not bytes: chr(8364) is a euro sign, and ord of it returns 8364 rather than the length of its UTF-8 encoding.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

ord — documented in the same entry.