Go中的fmt.Println()和println()之间的区别
如下图所示,无论是fmt.Println()
和println()
给围棋相同的输出:Hello world!
但是:它们彼此之间有何不同?
片段1,使用fmt
包装;
package mainimport (
"fmt"
)
func main() {
fmt.Println("Hello world!")
}
片段2,不带fmt
包装;
package mainfunc main() {
println("Hello world!")
}
回答:
println
是内置函数(在运行时中),当fmt
程序包位于标准库中时,该函数可能会最终删除,该函数将保留下来。请参阅有关该主题的规范。
对于语言开发人员来说,println
没有依赖关系是很方便的,但是方法是使用fmt
软件包或类似的东西(log
例如)。
如您在实现中所看到的,这些print(ln)
功能并非旨在远程支持其他输出模式,而主要是调试工具。
以上是 Go中的fmt.Println()和println()之间的区别 的全部内容, 来源链接: utcz.com/qa/424654.html