Threadon / Builtins

Builtins

print, input, len, and chr

print

print writes values to standard output, separated by spaces, ending with a newline.

print("Hello,", 1, 2.5, True)
Hello, 1 2.500000 True

Each type formats its own way:

TypeOutputExample
Int32, Int8digits, with a minus sign if negativeprint(-3) → -3
Float32always 6 decimal placesprint(2.5) → 2.500000
BoolTrue or Falseprint(True) → True
Stringthe text itself, quotes not includedprint("hi") → hi
Listthe items between square bracketsprint([1, 2]) → [1, 2]
Dictthe key/value pairs between bracesprint({"a": 1}) → {a: 1}

Strings are printed as-is, so spaces inside them are preserved:

print("a b c")
a b c

print() with no arguments prints just a newline. A NoneType value prints as None:

def nothing() -> NoneType
    return

def main() -> Int32
    print(nothing())
    return 0
None

input

input reads one line from standard input and returns it as a String. The trailing newline is stripped.

name: String = input()

Give it a prompt and the prompt is printed first, with no trailing newline, so your input lands on the same line:

n: Int32 = Int32(input("Enter a number: "))
print(n + 1)
Enter a number: 41 42

If input runs out of data (for example at the end of a redirected file), it returns an empty string. Watch out: converting that empty string with Int32("") is a runtime error, and only caught in debug mode. The 07_conversion example on the Examples page shows the safe pattern.

len

len returns the number of items in a collection, as an Int64. It only takes a List or a Dict — passing a String fails to compile with Function 'len' expects a List or Dict, got String (strings have no length function yet; the workaround is a manual loop, described on the Strings page).

names: List[String] = ["ann", "bob", "clyde"]
print(len(names))
3

The empty collection has length 0. len is handy with for loops and indexing.

Related builtin: dict_key(d, i) returns the key of a Dict at position i (an Int64). It exists mostly as the machinery behind for key in d, but you can call it yourself if you want to step through a dict by index.

ages: Dict[String, Int32] = {"ann": 30, "bob": 40}
print(dict_key(ages, Int64(0)))
ann

chr

chr(code) takes an Int32 code point (0–255) and returns a one-character String holding that byte. It is how you build characters that have no literal escape, like the ANSI escape byte 27 that the colorama module uses:

print(chr(65))
A

Codes outside the byte range are silently truncated to their low 8 bits.

Cast functions

Int8, Int16, Int32, Int64, Float16, Float32, Float64, Bool, and String are all built-in functions that convert values. String(...) turns numbers and bools into text — print(String(3.5)) prints 3.500000 — and is covered on the Casts page together with the rest.