From the course: Go Essentials: Concurrency, Connectivity, and High-Performance Apps

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

Maps

Maps

- [Instructor] A map is a data structure where keys points to values. The keys and the values must be of the same type. So here we have a map of stocks. The keys are all strings, and the values are all float64s. We have the Amazon, the Google and the Microsoft stock. And we have to have the last trailing comma. The one right here. And we can use the built-in len to print out the length of the map. And this is going to print three. When we count len, we count the number of keys. If you want to get a value, we are going to use the square brackets. So we're getting the value of the Microsoft stock. If you're looking for a stock that is not in the map or a key that is not in the map, we are going to get the zero value for the values in the map. In this case, the values are float64. So the zero value is the number zero. If you want to know if a value is in the map or not, we can use two values on the left side of the…

Contents