Assignments

assignment

= is used for assigning. The values of multiple variables can be changed in one line. In this way, their values can be swapped without an intermediary variable.

var age int age = 21 // = is used for assigning. println age var a, b int = 0, 1 a, b = b, a // The values of multiple variables can be changed in one line. println a, b // 1, 0

= vs :=

:= is used for declaring and initializing. Multiple variables can be declared and intialized at one line.

age := 21 // age is declared and initialized to 21 println age a, b := 0, 1 // multiple variables can be declared and intialized at one line. a, b = b, a println a, b // 1, 0

Next example: Types