You can create a map with a value of type complex in Go by declaring a map with complex128
as its value type. Here's an example:
main.go321 chars14 lines
In the example above, we declare a map m
with the key's type as string, and the value's type as complex128
. We then initialize the map using the make
function. Finally, we set and access values in the map using the square bracket syntax.
Note that it's also possible to use the shorthand declaration syntax to create a map:
main.go33 chars2 lines
This shorthand syntax is equivalent to the longer syntax we used in the first example.
gistlibby LogSnag