Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics (Retired) Ruby Methods Methods in Ruby

Gaoyuan Chen
Gaoyuan Chen
2,546 Points

what's the difference between puts and print in ruby?

I found that both of them can print out the result and when I use print instead of puts, it showed me "Adding 2 and 57" something instead of "Adding 2 and 2"

3 Answers

TL;DR: puts adds a new line (after each argument); print does not. That's all.

James Gill: Can you expand on what the vocab word line means? Or can you use an example?

Whew! For me Maciej, that's a lot of text to weed through!

@abbymann "line" means a new line, like pressing Enter/Return on the keyboard.

So: "print" prints the string and stops at the end of it; "puts" prints the string, then places the cursor on the next (blank) line.