Back to Course
Fundamentals

Go Variables and Data Types Explained with Practical Examples

Declaring Variables in Go

var name string = "Alice"
var age int = 25
count := 10          // short variable declaration (type inferred)

Basic Data Types

  • Numeric typesint, int8/16/32/64, float32, float64
  • Booleanbool, holds true or false
  • Stringstring, an immutable sequence of bytes
  • Complex typescomplex64, complex128 (rarely used)

Zero Values

Unlike some languages, Go initializes variables to a "zero value" if not explicitly assigned — 0 for numbers, "" for strings, and false for booleans.

var x int      // x = 0
var s string   // s = ""
var b bool     // b = false

Ready to master real-world Go skills?

Learn Go hands-on with mentor-led, live sessions.

Explore Course