Ad space (banner)
๐ŸนGo Lessons
Lesson 3 / 68

Working with Variables

In this lesson you will learn the basic way to use variables in Go and understand its concise, type-inferred declarations. This is for anyone searching for "Go variables how to use" or "Go := how to use".

A variable is like a labelled box that stores a value under a name. := declares a variable without writing its type (type inference). fmt.Printf gives you formatted output.

The sample code declares name := "Alice" and age := 14 with :=, then assembles a message with format verbs in fmt.Printf("Hello, %s! You are %d years old\n", name, age). %s is the verb for a string and %d for an integer.

A common stumbling block for beginners is the strictness that comes with a statically typed language where types are fixed at compile time. It catches mistakes before you run, but a type mismatch is an immediate compile error. Go also has its own visibility rule worth noting: starting a name with a capital letter makes it "exported" and visible from other packages.

In real-world development this type inference lets you skip verbose type declarations while keeping the safety of compile-time type checking, which is why Go is trusted even in large systems.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Go directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)