34 lines
568 B
Go
34 lines
568 B
Go
// constants are used to give names to literals
|
|
// There is no way to declare that a value is immutable
|
|
// Use constants for hard-coded package level variables
|
|
|
|
// constants can be typed or untyped
|
|
// leave them untyped for flexibility (can use an untyped int constant in a func that takes a float etc)
|
|
// or hardcode them if needed
|
|
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
const x int = 10
|
|
|
|
const (
|
|
idKey = "id"
|
|
nameKey = "name"
|
|
)
|
|
|
|
const z = 20 * 10
|
|
|
|
func main() {
|
|
const y = "hello"
|
|
|
|
fmt.Println(x)
|
|
fmt.Println(y)
|
|
|
|
x = x + 1
|
|
y = "bye"
|
|
|
|
fmt.Println(x)
|
|
fmt.Println(y)
|
|
}
|