Go 中 fmt.Println() 和 println() 的区别
技术问答
253 人阅读
|
0 人回复
|
2023-09-12
|
无论如何,如下图所示fmt.Println()和println()同样输出围棋:Hello world!1 b& i& N* d+ o4 S9 k% {
但它们之间有什么区别呢?
: n' S) V, z0 o. P7 T) M: fSnippet 1,使用fmt包;
; ^8 H8 ]3 y1 F. @& u) Gpackage mainimport "fmt")func main() fmt.Println("Hello world!")}
W5 p) z4 Y, T) q5 C! c Snippet 2,不带fmt包;
( [! y% w2 ?# t( Epackage mainfunc main() println("Hello world!")}) v6 X) s: `' k. U# G2 |4 N9 f
' b. g" W4 G" s9 A! r5 L. K
解决方案: " c& {8 t, p6 ]% Y4 x: W5 J9 v
println内置函数(进入运行时)最终可能会被删除fmt包装在标准库中,它将继续存在。请参考本主题的规范。- X$ c/ c0 A( P) B$ c
对言开发人员,println不依赖项很方便,但要走的路是用的fmt包或类似的东西(log例如)。# N4 H) k) b, a2 m& a
正如您在实现中所看到的,这些print(ln)函数甚至不是为远程支持不同的输出模式而设计的,主要是调试工具。 |
|
|
|
|
|