What is the difference between print and puts?

puts adds a new line to the end of each argument if there is not one already.

print does not add a new line.


For example:

puts [[1,2,3], [4,5,nil]] Would return:

1
2
3
4
5

Whereas print [[1,2,3], [4,5,nil]]
would return:

[[1,2,3], [4,5,nil]]

Notice how puts does not output the nil value whereas print does.

Leave a Comment