Printing an output


Are there any differences between

print i


print "#{i}"?


yes, #{} allows us to insert a variable into a string:

puts "the value of i is: #{i}"

you still have open topics, please reply to those. If the replies topics solve the issue please use the marked as solved button.


Okie, now I get the differences between those two lines. The first one is a direct way of printing out the variable, and the second one is when we need to insert the value into a string. Both produce the same output anyway.

And I’m new to Codecademy forum, still trying to get a handle on this site. Thanks for the reminder.


in this case:

print i
print "#{i}"

yes, they show the same output.

However, the data types are not the same:

puts i.class
puts "#{i}".class

this is important!!

(.class is just a way to get the data type, don’t worry too much about it yet)

furthermore, i showed the potential for #{}:

puts "the value of i is: #{i}"

that you can print additional information with the variable, which can be useful


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.