fmt.Print and fmt.Println

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!

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

4 Likes

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

Thank you @Zyl1 for simple example.

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