Go—Range (Basics)

Go has an almost Python-like function: Range.
Range is used to iterating over elements in a lot of different Go data structures.

Of course, we can range over slices and arrays, like:

We get both the value and index when using the range function, though in the above example we didn’t use it.

But we can also use range to go over the items on a map, getting both the key and value of each item on the map:

Another use of the range is to range over the Unicode points of a string in go:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nikolaj Johannes Skole Jensen

Fullstack developer living in Denmark. Experience with both Web- and App development.