Lesson 3: Data Types¶
Big Picture¶
flowchart TD
T["Go types"] --> N["Numeric"]
T --> S["string"]
T --> B["bool"]
N --> I["integers<br/>int8 · int16 · int32 · int64<br/>uint8 · uint16 · uint32 · uint64"]
N --> F["floats<br/>float32 · float64 (default)"]
S --> R["made of bytes,<br/>runes (int32) = unicode code points"]
I -.->|"Go requires EXPLICIT conversion"| C["float64(i)"]
Go has no implicit conversions — mixing int and float64 won't compile. Convert explicitly, always.
Concepts¶
Integer Types¶
| Type | Size | Range |
|---|---|---|
int8 |
8 bits | -128 to 127 |
int16 |
16 bits | -32768 to 32767 |
int32 |
32 bits | -2B to 2B |
int64 |
64 bits | Very large |
uint8 |
8 bits | 0 to 255 |
Floating Point¶
float32— 32-bit precisionfloat64— 64-bit precision (default)
Strings¶
Type Conversion¶
Code Walkthrough¶
Exercises
- Declare an
int8and try assigning 200 — what happens? - Print the byte length vs rune count of a string containing an emoji.
- Convert a
float64toint— where does the fractional part go?
Check Your Understanding¶
#
Which conversion is REQUIRED in Go?
#
A rune in Go is an alias for: