create a map with a key and value of type float in go

To create a map with a key and value of type float in Go, we can use the following syntax:

main.go
myMap := make(map[string]float64)
34 chars
2 lines

In the syntax above, myMap is a variable of type map with a key of type string and a value of type float64. We can customize the key and value types according to our needs.

We can then add key-value pairs to the map using the following syntax:

main.go
myMap["item1"] = 10.5
myMap["item2"] = 20.0
44 chars
3 lines

To access the value of a specific key in the map, we can use the following syntax:

main.go
value := myMap["item1"]
fmt.Println(value) // Output: 10.5
59 chars
3 lines

We can also delete a key-value pair from the map using the delete function:

main.go
delete(myMap, "item2")
23 chars
2 lines

I hope this helps!

gistlibby LogSnag