Ruby: Print
To print, use p
, puts
, print
.
# ruby a = 5 b = "rabbit" p a, b, 3 # prints each on a new line. =begin this is a multi-line comment p a, b, 3 can be written as p(a, b, 3) parenthesis are often not necessary =end
What is the difference between {puts, print, p}?
puts
prints in a human readable form, and adds newline after each argument. For example, string is printed without quotes, array are printed without the brackets or separators.print
is similar to “puts” but does not add newline.p
prints in a technical form. For example, string will include the quotes. This is good for debugging.