gpt4 book ai didi

golang 我在 println() 之后使用 fmt.Println() 但是

转载 作者:IT王子 更新时间:2023-10-29 00:37:42 28 4
gpt4 key购买 nike

这是我的代码(golang)

func main() {
names := []string{"1", "2", "3"}

for index, name := range names {
println(index, name)
}

myMap := map[string]string{
"A": "Apple",
"B": "Banana",
"C": "Charlie",
}

for key, val := range myMap {
fmt.Println(key, val)
}
}

这是结果

0 1
B Banana
1 2
2 3
C Charlie
A Apple
  1. 为什么 names 和 myMap 混在一起了?
  2. 为什么 myMap 的顺序不同?

最佳答案

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.

func Println

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

fmt.Println formats using the default formats for its operands and writes to standard output.

fmt.Println 写入标准输出 (stdout) 和 println 写入标准错误 (stderr),两个不同的非同步文件。

Map types

A map is an unordered group of elements of one type, called the element type, indexed by a set of unique keys of another type, called the key type.

For statements

A "for" statement specifies repeated execution of a block.

The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next.

map 元素是无序的。未指定迭代顺序。

关于golang 我在 println() 之后使用 fmt.Println() 但是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35931166/

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