String

Text value collection. Created by string literals or str(value), then read by length/index/loop operations.

Syntax

String

This class cannot be constructed directly.

Returns

—

Example

name = "Start"
if name:
    first_char = name[0]
    text(first_char)

Methods

24 methods

String.literal

Create text directly with single or double quotes.

Syntax

"hello"

Parameters

NameDescription
textString
String content between quotes.
Required · Positional or named
No default

Returns

String — A new string value.

Example

label = "Start"
text(label)

String.cast

Convert a number, boolean, or other value to text. Large or deeply nested structured values use a bounded preview with explicit omission markers, while a direct string remains unchanged.

Syntax

str(value, /)

Parameters

NameDescription
valueAny?
Value to convert into text.
Required · Positional only
No default

Returns

String — Converted text value.

Example

attempt = 3
line = str(attempt)

String.length

Count how many characters are in the string.

Syntax

len(string, /)

Parameters

NameDescription
stringString
String value to count.
Required · Positional only
No default

Returns

Int — Character count.

Example

label = "Play"
count = len(label)        # returns 4

String.index_access

Read one character by index. Negative indexes count from the end.

Syntax

string[index]

Parameters

NameDescription
stringString
Source string.
Required · Positional or named
No default
indexInt
Character index. Use -1 for the last character.
Required · Positional only
No default

Returns

String? — One-character string, or None if out of range.

Example

label = "Play"
first = label[0]          # returns 'P'
last = label[-1]          # returns 'y'

String.slice

Copy a substring using Python-style slicing. Omitted bounds use the start or end; negative indexes count from the end.

Syntax

string[start:end[:step]]

Parameters

NameDescription
startInt
First character index to include.
Optional · Positional only
Default: start of string
endInt
Stop before this character index.
Optional · Positional only
Default: end of string
stepInt
Distance between characters. Cannot be 0; negative values read backward.
Optional · Positional only
Default: 1

Returns

String — A new string slice, clamped to the available range.

Example

label = "abcdef"
middle = label[1:4]       # returns 'bcd'
tail = label[-3:]         # returns 'def'
reverse = label[::-1]     # returns 'fedcba'

String.lower_method

Return a lowercase copy of the string.

Syntax

string.lower()

Returns

String — Lowercase string.

Example

label = "PLAY"
text(label.lower())

String.upper_method

Return an uppercase copy of the string.

Syntax

string.upper()

Returns

String — Uppercase string.

Example

label = "play"
text(label.upper())

String.strip_method

Trim whitespace, or the provided characters, from both ends.

Syntax

string.strip(chars=None, /)

Parameters

NameDescription
charsString?
Characters to trim instead of whitespace.
Optional · Positional only
Default: None

Returns

String — Trimmed string.

Example

label = "  Play  "
clean = label.strip()

String.lstrip_method

Trim whitespace, or the provided characters, from the left side.

Syntax

string.lstrip(chars=None, /)

Parameters

NameDescription
charsString?
Characters to trim instead of whitespace.
Optional · Positional only
Default: None

Returns

String — Left-trimmed string.

Example

label = "...Play"
clean = label.lstrip(".")

String.rstrip_method

Trim whitespace, or the provided characters, from the right side.

Syntax

string.rstrip(chars=None, /)

Parameters

NameDescription
charsString?
Characters to trim instead of whitespace.
Optional · Positional only
Default: None

Returns

String — Right-trimmed string.

Example

label = "Play..."
clean = label.rstrip(".")

String.startswith_method

Check whether the selected slice starts with a prefix.

Syntax

string.startswith(prefix, start=0, stop=len(string), /)

Parameters

NameDescription
prefixString
Prefix to test.
Required · Positional only
No default
startInt
Start index for the check.
Optional · Positional only
Default: 0
stopInt
Stop index for the check.
Optional · Positional only
Default: len(string)

Returns

Boolean — true when the prefix matches.

Example

label = "Play"
ready = label.startswith("Pl")

String.endswith_method

Check whether the selected slice ends with a suffix.

Syntax

string.endswith(suffix, start=0, stop=len(string), /)

Parameters

NameDescription
suffixString
Suffix to test.
Required · Positional only
No default
startInt
Start index for the check.
Optional · Positional only
Default: 0
stopInt
Stop index for the check.
Optional · Positional only
Default: len(string)

Returns

Boolean — true when the suffix matches.

Example

label = "Play"
ready = label.endswith("ay")

String.find_method

Find the first substring index, or return -1 when absent.

Syntax

string.find(sub, start=0, stop=len(string), /)

Parameters

NameDescription
subString
Substring to find.
Required · Positional only
No default
startInt
Start index for the search.
Optional · Positional only
Default: 0
stopInt
Stop index for the search.
Optional · Positional only
Default: len(string)

Returns

Int — First matching index, or -1.

Example

label = "start button"
index = label.find("button")

String.index_method

Find the first substring index and fail visibly when absent.

Syntax

string.index(sub, start=0, stop=len(string), /)

Parameters

NameDescription
subString
Substring that must exist.
Required · Positional only
No default
startInt
Start index for the search.
Optional · Positional only
Default: 0
stopInt
Stop index for the search.
Optional · Positional only
Default: len(string)

Returns

Int — First matching index.

Example

label = "start button"
index = label.index("button")

String.replace_method

Return a copy with occurrences of old text replaced.

Syntax

string.replace(old, new, count=-1, /)

Parameters

NameDescription
oldString
Text to replace.
Required · Positional only
No default
newString
Replacement text.
Required · Positional only
No default
countInt
Maximum replacements; negative means all.
Optional · Positional only
Default: -1

Returns

String — Updated string copy.

Example

label = "start start"
once = label.replace("start", "play", 1)

String.split_method

Split a string into a list of text parts.

Syntax

string.split(sep=None, maxsplit=-1, /)

Parameters

NameDescription
sepString?
Separator text. None splits on whitespace.
Optional · Positional only
Default: None
maxsplitInt
Maximum split count; negative means all.
Optional · Positional only
Default: -1

Returns

list — List of string parts.

Example

raw = "a,b,c"
parts = raw.split(",")

String.join_method

Join an iterable of strings using this string as the separator.

Syntax

string.join(iterable, /)

Parameters

NameDescription
iterableIterable<String>
String values to join.
Required · Positional only
No default

Returns

String — Joined string.

Example

parts = ["a", "b", "c"]
line = ",".join(parts)

String.count_method

Count non-overlapping substring occurrences.

Syntax

string.count(sub, start=0, stop=len(string), /)

Parameters

NameDescription
subString
Substring to count.
Required · Positional only
No default
startInt
Start index for the count.
Optional · Positional only
Default: 0
stopInt
Stop index for the count.
Optional · Positional only
Default: len(string)

Returns

Int — Occurrence count.

Example

label = "banana"
count = label.count("an")

String.isalpha_method

Check whether the string is non-empty and all characters are letters.

Syntax

string.isalpha()

Returns

Boolean — true for letters only.

Example

label = "Play"
ok = label.isalpha()

String.isdigit_method

Check whether the string is non-empty and all characters are digits.

Syntax

string.isdigit()

Returns

Boolean — true for digits only.

Example

value = "123"
ok = value.isdigit()

String.isalnum_method

Check whether the string is non-empty and all characters are letters or digits.

Syntax

string.isalnum()

Returns

Boolean — true for letters or digits only.

Example

value = "A123"
ok = value.isalnum()

String.isspace_method

Check whether the string is non-empty and all characters are whitespace.

Syntax

string.isspace()

Returns

Boolean — true for whitespace only.

Example

value = "   "
ok = value.isspace()

String.for_loop

Iterate characters from left to right.

Syntax

for ch in string:

Parameters

NameDescription
chString
Current character in the loop.
Required · Positional or named
No default
stringString
String to iterate.
Required · Positional or named
No default

Returns

None — No direct return value. Executes once per character.

Example

word = "Go"
for ch in word:
    text(ch)

String.truthy_check

Check whether the string is empty or not.

Syntax

if string | if not string

Parameters

NameDescription
stringString
String used in the condition.
Required · Positional or named
No default

Returns

Boolean condition — true when non-empty, false when empty.

Example

value = ""
if not value:
    text("empty")