Go和Print的区别

时间:2019-08-21 10:07:39

标签: go

在Go lang中,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]

有人可以请问这是怎么工作的,以及Go语言中“ print()”和“ fmt.Print()”分别做什么。

1 个答案:

答案 0 :(得分:0)

print()是内置函数,不能保证保留该语言。看到buildin.go