← Back to Ruby Course | Chapter 1: Setup & Basics | Lesson 5 of 7

puts, print, and p

In this page:

  1. puts, print, and p

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

markup
puts "Hello with puts"
print "Hello with print"
print "\n"
p "Hello with p"
p [1, 2, 3]
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.