Constants

Constants are declared like variables, but with the const keyword.

Constants can be character, string, boolean, or numeric values.

Constants cannot be declared using the := syntax.

constants.go

  1. package main
  2. import "fmt"
  3. const Pi = 3.14
  4. func main() {
  5. const World = "世界"
  6. fmt.Println("Hello", World)
  7. fmt.Println("Happy", Pi, "Day")
  8. const Truth = true
  9. fmt.Println("Go rules?", Truth)
  10. }