What is the difference between Puts and Print statements?


#1

I cant understand differnece between print and put


#2

It's explained in the course:

The print command just takes whatever you give it and prints it to the screen. puts (for "put string") is slightly different: it adds a new (blank) line after the thing you want it to print.

If you need examples:

print "yili"
print "yolo"

will give:

"yiliyolo"

puts "yili"
puts "yolo"

will give:

"yili
yolo"


#3

Thank You For Telling This.


#4

I'm still not understanding how I'm supposed to reply to move forward


#5

My code with puts "yili" puts "yolo" give me: yili yolo nil


#6

Well my first reflex would be to tell you that there's something wrong with your code or how you read the result.

Can you post a screenshot of your code and the result?


#7

Here the screenshot: http://imgur.com/IlntEEs

The code is just:

 print "yolo"
 puts "yili"

And that gives me the nil, every time I use print or puts. I searched through the forums and there's a lot of people with this problem, and they think is a codecademy bug.


#8

nil is perfectly normal, it's what puts and print return, it just means "nothing".

print "yolo"
puts "yili"

will obviously output "yoloyili", since "print" does NOT output a new line after the text.


#9

But what if I don't want to see the "nil" at the end? How can I make it stop printing nil?


#10

It doesn't print it, it just returns it (and yes, it displays it, but if it was a "real" program, you wouldn't get "nil" in the output).

As far as I know, you can't get rid of it, but there are A LOT of things I don't know about Ruby.


#11

it does not print it says you can not print


#12

I still don't understand how to make that space even happen though? I'm an absolute beginner, someone please help! :confused:


#13

I still wasn't understanding the explanation. Thank you for the examples, I finally got it ^__^


#14

Heading

I was just stuck on this for almost 20 mins trying to figure it out
first I was only typing down,
"Hello"
"Hello"
"Hello"
"Hello!Hello!Hello"
what I was doing wrong is,
I wasn't telling the program what I was doing,
the right way to tell the program is,
put "Hello"
"Hello"
"Hello"
print "Hello!Hello!Hello"

see the difference first in I wasn't putting put or print that why the program didn't see what you were doing.
: