go - Go 中 Print 和 print 的区别

标签 go

<分区>

Go 语言中的 fmt.Print("print something") 和 just print("print something") 之间有什么区别。

var a int
fmt.Print("In Print ", &a, "\n ")
print("In print ", &a, "\n")

两者提供相同的结果。

结果:

In Print 0xcSameAddressLocation
In print 0xcSameAddressLocation 

但是当我这样做时:

ar := []int{1, 2, 3, 4, 5, 6, 7, 8}
print("In print ", &ar, "\n")
print("In print ", ar[0], "\n")
print("In print ", ar, "\n")
fmt.Print("In fmt.Print ", &ar, "\n")
fmt.Print("In fmt.Print ", &ar[0], "\n")
fmt.Print("In fmt.Print ", ar[0], "\n")
fmt.Print("In fmt.Print ", ar, "\n")

结果:

In print 0xcAddressLocation1
In print 1
In print [8/8]0xcAddressLocation2
In fmt.Print &[1 2 3 4 5 6 7 8]
In fmt.Print 0xcAddressLocation2
In fmt.Print 1
In fmt.Print [1 2 3 4 5 6 7 8]

有人可以问一下它是如何工作的以及“print()”和“fmt.Print()”分别在 Go 语言中做了什么。

最佳答案

print() 是内置函数,不能保证保留在语言中。参见 builtin.go

关于go - Go 中 Print 和 print 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57589221/

相关文章:

database - Golang gocql无法连接到Cassandra(使用Docker)

multithreading - 即使使用 GOMAXPROCS(4),GoLang 程序也在单线程上执行

web - Golang 路线不起作用

postgresql - 我应该如何将Postgres日期类型分配给变量

go - Paho MQTT golang 用于多个模块?

json - 使用反射在 Go 中创建 map

go - 将顺序测试分散到 4 个 go 例程中,如果一个失败则终止所有例程

go - Go中的替代导入语法

go - 如何将 HashiCorp 配置语言转换为 JSON?

Golang 反向代理返回 Not found 或 Forbidden 错误