Difference between fmt.Println() and println() in Go

前端 未结 5 1668
北海茫月
北海茫月 2020-12-07 12:02

As illustrated below, both fmt.Println() and println() give same output in Go: Hello world!

But: how do they differ from each

5条回答
  •  离开以前
    2020-12-07 12:46

    println is an built-in function (into the runtime) which may eventually be removed, while the fmt package is in the standard library, which will persist. See the spec on that topic.

    For language developers it is handy to have a println without dependencies, but the way to go is to use the fmt package or something similar (log for example).

    As you can see in the implementation the print(ln) functions are not designed to even remotely support a different output mode and are mainly a debug tool.

提交回复
热议问题