2022-12-03

This commit is contained in:
2022-12-03 18:29:02 +00:00
parent f559e0dc2a
commit ccbb0b2294
8 changed files with 122 additions and 0 deletions

33
chapter-2/03_const.go Normal file
View File

@@ -0,0 +1,33 @@
// 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)
}