Quidest?

Assigning more than one value in Go

ยท Lorenzo Drumond

When you have several assignments to do, Go has a nice feature to help you: the tuple assignment. A tuple is an ordered list of things.

Suppose we have three variables a, b, and c, and we want to assign them the values 1, 2, and 3 respectively.

We can write

1a, b, c := 1, 2, 3

var x, y = 2, 3 is slightly safer to use than x, y := 2, 3. The former ensures that both x and y do not already exist in the current scope.

References

#basics #assignment #programming #golang #tuples #statement