Reference · Strings

split

signature
split(str, str=) -> list

What it does

Cuts text at every occurrence of a separator and gives the pieces as a list of strings. The separator is plain text, not a pattern; for a pattern use re.split. Without a separator, the text is split at spaces; with the empty separator, into its characters.

Examples

print(split("a,b,c", ","))print(split("2026-10-29", "-"))print(split("one  two", " "))print(split("a b c"), split("abc", ""))
output
["a", "b", "c"]["2026", "10", "29"]["one", "", "two"]["a", "b", "c"] ["a", "b", "c"]

Edge cases

print(split(",a,,b,", ","))print(split(",a,,b,", ",") | filter((p) => p != ""))print(split("", ","), split("abc", ","))print(split("añb", ""))
output
["", "a", "", "b", ""]["a", "b"][""] ["abc"]["a", "ñ", "b"]

Errors

A text or a separator that is not a string is a runtime error, not an error value.

this one fails
print(split(42, ","))
output
line 1: `split` expects a str as argument 1, got int

Chaining

print("k=v" | split("=") | first)print("a b c" | split(" ") | map(upper) | join("-"))let [key, value] = split("name=Ann", "=")print(key, value)
output
kA-B-Cname Ann

See also

join, re.split, trim, slice

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

Thread 0 posts

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