TL ; DR:
Variables are containers for storing values.
In Go, you can declare a variable with var:
var car string = "Toyota"
var experience int = 3
Inside a function, Go also lets you use short declaration with :=:
car := "Toyota"
experience := 3
Full lesson:
A piece of information lives in memory, and we use a variable to store and label that data.
A variable declaration can include:
- a name, such as
name - a type, such as
stringorint - a value, such as
"AlgoCademy"
var name string = "AlgoCademy"
var age int = 10
fmt.Println(name)
fmt.Println(age)
The output is:
AlgoCademy
10
Assignment
Follow the Coding Tutorial and let's create some variables.
Hint
Use var for the typed declarations and := for the short declaration step.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
