Variables and Primitive Types
AvailableLesson 1 of 25 · Syntax · Easy
The big idea
A variable gives a name to a value so your Go program can remember it. Inside func main(), the easiest way to make a variable in Go is with :=: Go figures out the type from the value on the right, and you do not need semicolons at the end of lines.
Think of it like this: Think of `:=` in Go as a quick label-maker: `x := 5` creates a new box named `x` and puts `5` inside in one step.
Read the lesson
A variable gives a name to a value so your Go program can remember it.
Inside func main(), the easiest way to make a variable in Go is with :=:
age := 20 // a whole number (int)
price := 9.99 // a decimal number (float64)
name := "Maya" // text (string)
isReady := true // true or false (bool)
Go figures out the type from the value on the right, and you do not need semicolons at the end of lines. (You can also write var age int = 20 if you prefer to spell out the type.)
Quick check
What is the shortest way to create a new variable named age set to 20 inside a Go function?
Your challenge
Inside main(), create a variable named x and set it to 5 (type x := 5).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.variables-types (85% overlap). Variables & primitive types: compare let/const (JS), auto/int (C++), := (Go), let mut (Rust), and column types (SQL).
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Variables and Primitive Types.
Learn this first
Nothing needed - you can start here.