Reference · General

len

signature
len(str | list | map | html | null) -> int

What it does

The size of a value: a string's characters, a list's items, a map's keys, and an html value's bytes. null has length 0, so a missing list or text counts as empty. x.len is the same as len(x).

Examples

print(len("hello"), len([1, 2, 3]), len({ a: 1, b: 2 }))print(len(""), len([]), len({}))
output
5 3 20 0 0

Edge cases

print(len("é"), len("😀"), len("héllo"), len("a\nb"))print(len(null), len([[1, 2], [3]]))print(len(<b>hi</b>))print(len(split("", ",")))
output
1 1 5 30 291

Errors

A number, a boolean or a function has no length: that is a runtime error, not an error value. Convert a number with str first.

this one fails
print(len(42))
output
line 1: `len` expects a str, list or map, got int

Chaining

print(123 | str | len)print("a,b,c" | split(",") | len)print(["ab", "", "c"] | filter((s) => len(s) > 0) | len)
output
332

See also

slice, split, count, str, contains

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

Thread 0 posts

On len(): 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