Reputation: 79
this is my code(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)
}
}
and this is result
0 1
B Banana
1 2
2 3
C Charlie
A Apple
Upvotes: 6
Views: 1862
Reputation: 166569
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(a ...interface{}) (n int, err error)
fmt.Println formats using the default formats for its operands and writes to standard output.
fmt.Println writes to standard output (stdout) and println writes to standard error (stderr), two different, unsynchronized files.
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.
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.
Maps elements are unordered. The iteration order is not specified.
Upvotes: 10