GCGrowCarrer

Variables and Primitive Types

Available

Lesson 1 of 25 · Syntax · Easy

Mastery0% of 85%
1

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.
Key words (tap to learn):
2

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.)

3

Quick check

What is the shortest way to create a new variable named age set to 20 inside a Go function?

4

Your challenge

2 sample tests, 1 hidden

Inside main(), create a variable named x and set it to 5 (type x := 5).

Stuck? Get a hint (free)
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.

Mastery0%

Learn this first

Nothing needed - you can start here.