Remembering Things

Remembering Things

Remembering Things

Variables let you name values and reuse them later.

example.go
name := "Gopher"
age := 10
happy := true

Two characters: :=. That's Go's short variable declaration. No type keywords needed. Go looks at the value and picks the type for you. "Gopher" makes name a string. 10 makes age an int. true makes happy a bool.

>_Exercise

Exercise: Order Receipt

Create two variables using :=:

  • product with value "Coffee"
  • price with value 5

Print each on its own line so the output is exactly:

example.go
Coffee
5
Stuck? Reveal a hint to help you.
Hints (0/3)
Key Takeaway
Next UpValues that never change.