CODE/2022-11-23

Go println vs. fmt.Println

Go provides the built-in print and println functions as well as the fmt package's formatted output functions. They are not interchangeable for application logging or structured values.

Use fmt.Println for ordinary output

go_snippet
Go · 8 lines|
package main
import "fmt"
func main() {
values := []int{1, 2, 3}
fmt.Println("Values:", values)
}
fmt.Println writes to standard output, inserts spaces between arguments, and ends with a newline. It formats common values such as slices and structs; types may also customize formatting through interfaces such as fmt.Stringer.

Built-in print and println

go_snippet
Go · 5 lines|
package main
func main() {
println("debug value:", 42)
}
The built-ins are useful for simple bootstrapping and debugging, but the language specification does not guarantee their output format or destination. They do not provide the general formatting behavior of fmt, and not every value can be printed directly. Output interleaved with fmt.Println may appear in an unexpected order because destinations and buffering can differ.

Which should you choose?

Use fmt.Println, fmt.Printf, or a logging package for normal program output. Reserve print and println for temporary low-level debugging.
COMPANION ESSAYS / 思想脉络与互照篇目
同卷深读2026-05-22 ·

Installing Python 3 Alongside System Python on CentOS 7

同属「系统工程卷」脉络衍生思考与工程推演推演阅读 →
跨界互照2026-08-22 ·

我的书架:03|金融经管:经济运行、金融体系与企业治理

我的书架:03|金融经管:经济运行、金融体系与企业治理

跨领域对照思辨 · 从「思想随笔」视界互为印证推演阅读 →
RELATED INDEX / 相关阅读索引
柯航hang.ke·© 2014—2026
CC BY-NC 4.0·