Threadon / Builtins

Builtins

print and input

print

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

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

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
Bool1 or 0, not true/falseprint(True)1
Stringthe text itself, quotes not includedprint("hi")hi

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.

One thing print refuses: printing a NoneType value is a compile error. The message spells it out:

Error: Function 'print' cannot print a value of type NoneType at line 5

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.

Cast functions

Int8, Int16, Int32, Float16, Float32, and Bool are also built-in functions that convert values. (There is no String(...) conversion.) They get their own section on the Casts page.