Reference · General

str

signature
str(any) -> str

What it does

The value as text, written the way print writes it: a string is itself, a number its digits, a whole float with .0 and never in exponent form, a decimal its digits, a boolean true or false, null the word null, and a list or map as Quillo writes it, strings inside them quoted. It never fails, so it is the safe way to put anything into a template or a message.

On a server, an error Quillo made reads err("internal error") here, and its text goes to the log: it may hold an address with its password. print and error(r) have the text. In a page in production the browser hides it the same way, in text, a template, markup or an attribute, so a component made again in the browser shows no more than the server's page did; an error the program wrote, a server fn's and the page's own JavaScript's are shown as they are.

Examples

print(str(42), str(2.0), str(dec("1.50")), str(true), str(null))print(str([1, "x", null]), str({ a: 1, b: "x" }))print(len(str(12345)))
output
42 2.0 1.50 true null[1, "x", null] { a: 1, b: "x" }5

Edge cases

print(str(1e16), str(0.1 + 0.2), str(-0.0), str(1e-7))print(str(err("boom")), type_of(str(err("boom"))))print(str("already"), str(null))print(str(1916218016406818.3), str({ é: 1, 日本: 2, "a b": 3, "1a": 4 }), str(<p class="x">hi</p>))
output
10000000000000000 0.30000000000000004 -0.0 0.0000001err("boom") stralready null1916218016406818.2 { é: 1, 日本: 2, "a b": 3, "1a": 4 } <p class="x">hi</p>

Errors

str is never a runtime error and never an error value: every value has a text form, a function included. NaN and the infinities are NaN, inf and -inf.

print(str(float("nan")), str(float("inf")), str(upper))
output
NaN inf <builtin upper>

Chaining

print(123 | str | len)print([1, 2, 3] | map(str) | join("-"))print(2.5 | str | ends_with(".5"))
output
31-2-3true

See also

int, float, print, format_number, json.stringify

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On str(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo