gpt4 book ai didi

go - 在测试 golang 的 println 和 fmt.println 时需要帮助

转载 作者:IT王子 更新时间:2023-10-29 02:27:52 29 4
gpt4 key购买 nike

我写了一些简单的代码来测试 println 和 fmt.Println,但是当我运行代码时,它几乎每次都打印出不同的结果。我试图用谷歌搜索 println 和 fmt.Println 之间的区别,但一无所获。有没有人知道这两个功能的真正区别或优先级或顺序?

代码如下:

package main
import (
"fmt"
)

func main(){
println("a")
fmt.Println("b")
println("c")
fmt.Println("d")

p()
}

func p(){
println("e")
fmt.Println("f")
println("g")
fmt.Println("h")
}

谢谢!

最佳答案

Builtin functions

func println

func println(args ...Type)

The println built-in function formats its arguments in an implementation- specific way and writes the result to standard error. Spaces are always added between arguments and a newline is appended. Println is useful for bootstrapping and debugging; it is not guaranteed to stay in the language.

Package fmt

func Println

func Println(a ...interface{}) (n int, err error)

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

fmt.Println() 使用 stdoutprintln() 使用 stderr

正如预期的那样,具有不同目的的两个不同函数会给出不同的结果。

关于go - 在测试 golang 的 println 和 fmt.println 时需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31090022/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com