In Go it is good to use constants instead of regular variables to define identifiers for values that will not change during program execution. We use keyword "const" to define constants.
package main
import "fmt"
// global public constant
const Pi = 3.14
func main() {
//local string constant
const world = "δΈη"
fmt.Println("Hello", world)
fmt.Println("Happy", Pi, "Day")
//local Boolean constant
const truth = true
fmt.Println("Go rules?", truth)
}
Try it: https://go.dev/play/p/9mY4cwCCbDP
Notes:
Constants can be global or local. Usually global constants start with capital letters to be public. Local constants make sense to define with lowercase, but you can also use uppercase letters.
Constants are declared with the const keyword.
Constants can be character, string, boolean, or numeric values.
Constants must be initialized with literal using the assign symbol "=".
If you are geting older, increase the spead! ππΌπ
Β