This is a creation in Article, where the information may have evolved or changed.
<pre style= "margin-top:0px; margin-bottom:0px; " ><span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " ></span><pre name= "code" class= "plain" >package mainimport ("FMT") type Vertex struct {x, y int}var m map[st Ring]vertex = map[string]vertex{"Key1": Vertex{1, 2},//<---------note the comma "Key2" here: vertex{5, 6},//<--------- Again pay special attention to the comma here}func main () {//m["Key3"] = vertex{3, 4}//here in fact should make a judgment so modify it to this look if _, exists: = m["Key3"]; exists {//Determine the existence of this key in the map So is the modification operation m["Key3"] = Vertex{3, 4}} else {//To determine that the key does not exist in the map so it is added operation m["Key3"] = vertex{3, 4}}fmt. PRINTLN (m)//Output Map[key1:{1 2} key2:{5 6} key3:{3 4}]}
This map and Java compared to the wonderful, when the assignment, please pay attention to the two damned comma, at the same time to the map to append the key value pairs, directly write on it, although the understanding is very simple, but people are very uncomfortable ah, the ghost know this is inserted or modified, do not make it wrong, judge the insurance
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.