Variables with initializers

A var declaration can include initializers, one per variable.

If an initializer is present, the type can be omitted; the variable will take the type of the initializer.

variables-with-initializers.go

  1. package main
  2. import "fmt"
  3. var i, j int = 1, 2
  4. func main() {
  5. var c, python, java = true, false, "no!"
  6. fmt.Println(i, j, c, python, java)
  7. }