Why does print("hi") puts("1") Outputs "hi1" When puts("hi") print("1") Outputs hi 1? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does print("hi") puts("1") Outputs "hi1" When puts("hi") print("1") Outputs hi 1?

27th Feb 2017, 2:20 AM
Ethan
4 Answers
+ 8
puts outputs the text, and then adds a new line afterward. You can see that in the second example. print outputs the text only, without the extra newline. That's why the outputs are right next to each other in the first example.
27th Feb 2017, 2:36 AM
Tamra
Tamra - avatar
+ 1
puts() adds a newline after executing each argument and print() does not. (At least not by default) ie puts 1 2 3 4 5 outputs: 1 2 3 4 5 where print 1 2 3 4 5 outputs: 12345
27th Feb 2017, 2:42 AM
ChaoticDawg
ChaoticDawg - avatar
0
Or something like that
27th Feb 2017, 2:22 AM
Ethan
0
puts add newline..simple
27th Feb 2017, 3:49 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar