Course of Raku / Essentials / Built-in functions for printing

print

The print built-in routine does the following:

  1. Converts its arguments to a string by calling the Str method on them.
  2. Sends it to the STDOUT stream.

For simple data types, the output generated by print is similar to the output of say without the newline character at the end.

print 42;
print 'Raku';

These values are printed one after another. There is no newline at the end of the whole output, too.

$ raku t.raku
42Raku

For aggregate data, the result may differ from what you see with say. For example, try arrays and hashes:

my @data = 'alpha', 'beta', 'gamma';
print @data;

print "\n"; # To separate the parts

my %data = alpha => 1, beta => 2, gamma => 3;
print %data;

This is how the output looks like:

$ raku t.raku
alpha beta gamma
alpha	1
beta	2
gamma	3

The print routine can also be called as a method:

my @data = 'alpha', 'beta', 'gamma';
@data.print;

"\n".print;

Course navigation

Built-in functions for printing / say   |   Built-in functions for printing / put


💪 Or jump directly to the exercises to this section.

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська