go - Go中打印和打印的区别
问题描述
Go 语言中的 fmt.Print("print something") 和仅 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
推荐阅读
- python - 当父级被销毁/取消引用时,Tkinter 如何处理子小部件?
- python - 使用 Jupyter notebook 将具有多个工作表的 Excel 文件转换为多个 csv 文件
- spring-boot - 在 applcation.yml 中注入其他 yaml 文件?
- python - 当其中的任务失败时,自动将 Celery 链移动到死信队列
- mysql - MySql 表单查询过滤器或忽略 NodeJS 中列值的 WHERE 子句
- php - 在从输入框中清除输入后,Laravel Ajax 搜索将整个集合作为对查询的响应
- reporting-services - SSSR 参数在预览模式下改变位置
- python - 多个产品的 Python Prophet 需求预测:将所有预测保存到单个数据框中
- javascript - 如何创建一个循环来询问存储在对象数组中的问题,并创建带有答案的按钮?
- python - 如何在 Python 脚本上使用 setuid 位?