puts, print, and p
In this page:
puts, print, and p
puts prints a value followed by a newline, print prints without adding one, and p prints the value's inspected (debug) representation, including quotes around strings. p is especially useful while debugging since it makes the type of the value clearer than puts. All three accept multiple arguments.
Note: Use p instead of puts when debugging, since it shows exactly what type of value you have, quotes and all.
Example: puts, print, and p
puts "Hello with puts"
print "Hello with print"
print "\n"
p "Hello with p"
p [1, 2, 3]
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: