Data Types in Go — A Beginner's Guide
Every value in Go has a type. Understanding types is how you start thinking like the compiler.
Also available on YouTube • 1:01:00 watch time
Why Do Types Matter?
When you create a variable, Go needs to know what kind of value it's going to hold. Is it a whole number? A decimal? A piece of text? A yes-or-no answer? This isn't Go being fussy — it's Go being smart. Knowing the type in advance helps catch mistakes before your program even runs.
The Core Types You'll Use Every Day
Integers — Whole Numbers
For counting, indexing, or any number without a decimal point:
var age int = 21
var score int = 100
itemCount := 42
Go has several integer sizes (int8, int16, int32, int64), but in most cases, just using int is perfectly fine. Go picks a sensible size for your machine automatically.
Floats — Decimal Numbers
For prices, measurements, or anything that needs precision after the decimal point:
var temperature float64 = 36.6
pi := 3.14159
Use float64 by default. It gives you plenty of precision. float32 exists too, but you'll rarely need it unless you're working with very specific hardware.
Strings — Text
Any piece of text goes inside double quotes:
greeting := "Hello, welcome to Bits Bytes!"
language := "Go"
Strings in Go are immutable — once created, you can't change individual characters. But you can always create a new string from an old one.
Booleans — True or False
For yes/no decisions. There are only two possible values:
isLoggedIn := true
hasPermission := false
You'll use booleans constantly with if-else statements (which we'll cover in lesson 05). They're the foundation of every decision your program makes.
Remember: Go won't let you mix types. You can't add a string to an integer or compare a float with a boolean. This strictness might feel annoying at first, but it saves you from a whole category of bugs.
Type Conversion
Sometimes you need to convert between types. Go makes you do this explicitly — no behind-the-scenes magic:
x := 10 // int
y := float64(x) // now it's a float64
fmt.Println(y) // prints 10
This is Go saying: "I want you to know exactly what's happening with your data." It keeps things predictable.
Try It Yourself
Create one variable of each type — an integer, a float, a string, and a boolean. Print them all. Then try converting an integer to a float and printing the result.