Statement

Multiple assignment evaluation

Assignment evaluates relevant left-hand operands and all right-hand expressions before storing results from left to right. A left-hand index can therefore use the old value of another assigned variable. Example output: '1 [9 2]'.

Formal Syntax & Structure

go syntaxgo
a, b = b, a

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  i := 0  s := []int{1, 2}  i, s[i] = 1, 9  fmt.Println(i, s)}
Go Reference