Let us say, we have a Map that contains,
As 'Key' and 'Value' pair.
Now, let us say, we want to update the value of the 'Key', 'Pune' with 'Is a City in India'.
Where 'Pune' is the 'Key' and 'Is a City in India' is the new 'Value'.
Let us see in the below example.
package main import "fmt" func main() { x := map[string]string { "Pune" : "Is a City", "John": "Is a Name", "Go": "Is a Language"} x["Pune"] = "Is a City in India" for i,j := range x { fmt.Println("The value for the key ",i," is ",j) } }
So, in the above code we have created a 'Map' using braces '{}' and 'Key' and 'Value' pairs.
x := map[string]string { "Pune" : "Is a City", "John": "Is a Name", "Go": "Is a Language"}
And initialised to the variable 'x'.
Now, we are supposed to update the value of the 'Key', 'Pune' with value 'Is a City in India'.
So, we have used the below way to update it.
And the entry for the 'Key' 'Pune' is updated in the 'Map' with the new value, 'Is a City in India'.
And we get the below output,