To build upon nemo's answer:
println
is a function built into the language. It is in the Bootstrapping section of the spec. From the link:
Current implementations provide several built-in functions useful
during bootstrapping. These functions are documented for completeness
but are not guaranteed to stay in the language. They do not return a
result.
Function Behavior
print prints all arguments; formatting of arguments is implementation-specific
println like print but prints spaces between arguments and a newline at the end
Thus, they are useful to developers, because they lack dependencies (being built into the compiler), but not in production code. It also important to note that print
and println
report to stderr
, not stdout
.
The family provided by fmt
, however, are built to be in production code. They report predictably to stdout
, unless otherwise specified. They are more versatile (fmt.Fprint*
can report to any io.Writer
, such as os.Stdout
, os.Stderr
, or even a net.Conn
type.) and are not implementation specific.
Most packages that are responsible for output have fmt
as a dependency, such as log
. If your program is going to be outputting anything in production, fmt
is most likely the package that you want.
go build
, the output binary still has the text fromprintln
. – Uzial