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 trialGaoyuan Chen
2,546 Pointswhat'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
James Gill
Courses Plus Student 34,936 PointsTL;DR: puts
adds a new line (after each argument); print
does not. That's all.
Gaoyuan Chen
2,546 PointsThank you so much
A X
12,842 PointsWhew! For me Maciej, that's a lot of text to weed through!
James Gill
Courses Plus Student 34,936 Points@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.
A X
12,842 PointsA X
12,842 PointsJames Gill: Can you expand on what the vocab word line means? Or can you use an example?