fmt.Print and fmt.Println


(Martin “caubert” Kauber) #1

Hello…

my first post in this very helpful forum, so I try to make sense : )

My problem is. I don’t understand why does Println generate two extra bytes of whitespace in this code >
https://play.golang.org/p/PfvEE_TB_Ng

Really puzzled and I don’t know how to search for the answer as well, so any guidance would be great!

Thank you guys!


(Norbert Melzer) #2

Because both functions work as documented. println always adds spaces, print only when at least one of the two neighbors is not a string.


(MMulthaupt) #3

Println joins the arguments with spaces, while Print does not. (well, not always) You don’t need such a verbose example to see the difference: https://play.golang.org/p/nyLYT5wj8Da


(Yujin Boby) #4

Thank you @Zyl1 for simple example.