ac346fc3ee8039936c41b7a43641445472d9ce05 — coltonhurst 9 months ago fd938c5
Completed the package-variables-functions section of the 'Basics'
A basics/packages-variables-functions/1.1.15_constants.go => basics/packages-variables-functions/1.1.15_constants.go +20 -0
@@ 0,0 1,20 @@
+ /*
+ 	Notes 1.1.15
+ 
+ 	- In Go, constants are declared like variables but with the 'const' keyword
+ */
+ 
+ package main
+ 
+ import "fmt"
+ 
+ const Pi = 3.14
+ 
+ func main() {
+ 	const World = "世界"
+ 	fmt.Println("Hello", World)
+ 	fmt.Println("Happy", Pi, "Day")
+ 
+ 	const Truth = true
+ 	fmt.Println("Go rules?", Truth)
+ }

A basics/packages-variables-functions/1.1.16_numeric-constants.go => basics/packages-variables-functions/1.1.16_numeric-constants.go +31 -0
@@ 0,0 1,31 @@
+ /*
+ 	Notes 1.1.16
+ 
+ 	- You can declare constants in a group, like the factored import statement
+ 	- Numeric constants are precise values
+ 	- An untyped constant is implicitly typed
+ */
+ 
+ package main
+ 
+ import "fmt"
+ 
+ const (
+ 	// Create a huge number by shifting a 1 bit left 100 places.
+ 	// In other words, the binary number that is 1 followed by 100 zeroes.
+ 	Big = 1 << 100
+ 	// Shift it right again 99 places, so we end up with 1 << 1, or 2.
+ 	Small = Big >> 99
+ )
+ 
+ func needInt(x int) int { return x*10 + 1 }
+ 
+ func needFloat(x float64) float64 {
+ 	return x * 0.1
+ }
+ 
+ func main() {
+ 	fmt.Println(needInt(Small))
+ 	fmt.Println(needFloat(Small))
+ 	fmt.Println(needFloat(Big))
+ }