Variables (Remembering)
Telling the computer to remember something is called a variable.
How to remember things in Go
In Go, you can do it in a short and clear way.
x := 2026
y := "Hello, Go!"
In plain English:
Remember that x is 2026
Remember that y is "Hello, Go!"
The symbol := is a magic shortcut that means
“create a name and put a value in it right away.”
Say what you remembered
Let us check if the computer remembered correctly.
package main
import "fmt"
func main() {
x := 2026
y := "Hello, Go!"
fmt.Println(x)
fmt.Println(y)
}
Result:
2026
Hello, Go!
What can Go remember?
Go is very strict and clearly separates the types of things it remembers.
number := 2026 // integer (int)
decimal := 3.14 // float (float64)
text := "Hello" // string (string)
truth := true // boolean (bool)
Now you know how to store and retrieve information in Go.