Bird
0
0

What is the main difference between puts and print in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - Basics and Runtime
What is the main difference between puts and print in Ruby?
A<code>puts</code> adds a new line after output, <code>print</code> does not.
B<code>print</code> adds a new line after output, <code>puts</code> does not.
C<code>puts</code> outputs the object's inspect form, <code>print</code> outputs the string form.
D<code>print</code> outputs the object's inspect form, <code>puts</code> outputs the string form.
Step-by-Step Solution
Solution:
  1. Step 1: Understand puts behavior

    puts prints the given value and adds a new line automatically after it.
  2. Step 2: Understand print behavior

    print prints the given value but does not add a new line after it.
  3. Final Answer:

    puts adds a new line after output, print does not. -> Option A
  4. Quick Check:

    puts adds newline = C [OK]
Quick Trick: Remember: puts adds newline, print stays on same line [OK]
Common Mistakes:
  • Confusing which method adds a newline
  • Thinking print adds newline
  • Mixing up output formats of puts and print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes