For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
def print[*Ts: Writable](*values: *Ts.values, *, sep: StringSlice[StaticConstantOrigin] = StringSlice(" "), end: StringSlice[StaticConstantOrigin] = StringSlice("\n"), flush: Bool = False, var file: FileDescriptor = stdout)
Prints elements to the text stream. Each element is separated by sep and followed by end.
This function accepts any number of values, but their types must implement
the Writable trait. Most built-in types
(like Int, Float64, Bool, String) implement the
Writable trait.
For string formatting, you can use the
format() method
or, preferably, a template string
(TString, written t"...")
which interpolates expressions directly without allocating an
intermediate String.
Examples:
print("Hello, World!") # Hello, World!
print("The answer is", 42) # The answer is 42
print("{} is {}".format("Mojo", "🔥")) # Mojo is 🔥
var name = "Mojo"
print(t"{name} is 🔥") # Mojo is 🔥
Parameters:
- ​*Ts (
Writable): The elements types.
Args:
- ​*values (
*Ts.values): The elements to print. - ​sep (
StringSlice[StaticConstantOrigin]): The separator used between elements. - ​end (
StringSlice[StaticConstantOrigin]): The String to write after printing the elements. - ​flush (
Bool): If set to true, then the stream is forcibly flushed. - ​file (
FileDescriptor): The output stream.