Operator and syntax

Go assignment and short declarations

Assignment stores values into existing assignable destinations; short declaration introduces local variables and must introduce at least one new non-blank name in the same block. Tuple assignment evaluates right-hand expressions before assignment. Example output: '2 1'.

Formal Syntax & Structure

go syntaxgo
=; :=

Working Example

Example Snippetgo
package main
import (  "fmt")
func main() {  x, y := 1, 2  x, y = y, x  fmt.Println(x, y)}
Go Reference