点击(此处)折叠或打开

  1. // Variables
  2. package main

  3. import (
  4.     "fmt"
  5. )

  6. func main() {
  7.     var a string = "initial"
  8.     fmt.Println(a)
  9.     //You can declare multiple variables at once.
  10.     var b, c int = 1, 2
  11.     fmt.Println(b, c)
  12.     //Go will infer the type of initialized variables.
  13.     var d = true
  14.     fmt.Println(d)
  15.     //Variables declared without a corresponding initialization are zero-valued. For example, the zero value for an int is 0.
  16.     var e int
  17.     fmt.Println(e)
  18.     //The := syntax is shorthand for declaring and initializing a variable, e.g. for var f string = "short" in this case.
  19.     f := "short"
  20.     fmt.Println(f)
  21. }
转自https://gobyexample.com
09-06 17:13