mirror of https://github.com/golang/go.git
doc: sort map output in Effective Go
And explain that it does this. A minor change probably worth mentioning, although (#28782) I'd still like to freeze this document against any substantial changes. Fix #30568. Change-Id: I74c56744871cfaf00dc52a9b480ca61d3ed19a6b Reviewed-on: https://go-review.googlesource.com/c/go/+/165597 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
e90f572cd6
commit
c7408a8775
|
|
@ -1680,13 +1680,13 @@ maps. Here is a print statement for the time zone map defined in the previous s
|
|||
fmt.Printf("%v\n", timeZone) // or just fmt.Println(timeZone)
|
||||
</pre>
|
||||
<p>
|
||||
which gives output
|
||||
which gives output:
|
||||
</p>
|
||||
<pre>
|
||||
map[CST:-21600 PST:-28800 EST:-18000 UTC:0 MST:-25200]
|
||||
map[CST:-21600 EST:-18000 MST:-25200 PST:-28800 UTC:0]
|
||||
</pre>
|
||||
<p>
|
||||
For maps the keys may be output in any order, of course.
|
||||
For maps, <code>Printf</code> and friends sort the output lexicographically by key.
|
||||
When printing a struct, the modified format <code>%+v</code> annotates the
|
||||
fields of the structure with their names, and for any value the alternate
|
||||
format <code>%#v</code> prints the value in full Go syntax.
|
||||
|
|
@ -1710,7 +1710,7 @@ prints
|
|||
&{7 -2.35 abc def}
|
||||
&{a:7 b:-2.35 c:abc def}
|
||||
&main.T{a:7, b:-2.35, c:"abc\tdef"}
|
||||
map[string]int{"CST":-21600, "PST":-28800, "EST":-18000, "UTC":0, "MST":-25200}
|
||||
map[string]int{"CST":-21600, "EST":-18000, "MST":-25200, "PST":-28800, "UTC":0}
|
||||
</pre>
|
||||
<p>
|
||||
(Note the ampersands.)
|
||||
|
|
|
|||
Loading…
Reference in New Issue