Skip to main content

Mojo function

print

print[*Ts: Writable](*values: *Ts, *, sep: StringSlice[StaticConstantOrigin] = " ", end: StringSlice[StaticConstantOrigin] = "\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 both Stringable and Writable traits. If a type only implements Stringable, it can still be printed by first converting it to String.

For string formatting, use the format() function.

Examples:

print("Hello, World!")                   # Hello, World!

print("The answer is", 42)               # The answer is 42

print("{} is {}".format("Mojo", "πŸ”₯"))   # Mojo is πŸ”₯

Parameters:

  • ​*Ts (Writable): The elements types.

Args:

  • ​*values (*Ts): The elements to print.
  • ​sep (StringSlice): The separator used between elements.
  • ​end (StringSlice): 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.

Was this page helpful?