Stage 1 · Code
Variables, Types & Control Flow
Basic Types
Learn Go's built-in value types — numbers, strings, booleans, and characters — and how to convert safely between them.
Integer Types
Go has several integer types. The most common are int (platform-sized, usually 64-bit), int32, and int64. Use int by default unless you have a specific reason for a fixed size.
| Type | Size | Range / Notes |
|---|---|---|
| int | Platform-sized (usually 64-bit) | Signed; use for general counting |
| int8 / int16 / int32 / int64 | Fixed bit widths | When exact size matters |
| uint / uint8 / uint16 / uint32 / uint64 | Unsigned variants | No negative values |
| byte | 8-bit unsigned | Alias for uint8; raw binary data |
| rune | 32-bit signed | Alias for int32; a Unicode code point |
Floating-Point Types
Floating-point numbers represent real values with a decimal component. Go provides float32 and float64. Prefer float64 in almost all code — it has higher precision and is what most standard-library functions accept.
Floating-point numbers are stored in binary. Some decimal fractions cannot be represented exactly in binary, just as 1/3 cannot be represented exactly in decimal. This is not a Go bug; it is a property of IEEE 754 floating-point arithmetic used by virtually all programming languages.
string and rune
A string in Go is an immutable sequence of bytes, usually valid UTF-8 text. String literals appear in double quotes. A rune represents a single Unicode code point and is an alias for int32.
You cannot change a character in a Go string in place. To build or modify text, use strings.Builder, concatenation with +, or fmt.Sprintf. Strings are cheap to pass around because they are just a pointer and a length.
bool
A bool holds exactly two values: true or false. Go does not allow implicit conversions from integers or other types to bool. You must write an explicit comparison.
Explicit Conversions
Go never silently converts between numeric types. You must write the conversion explicitly using the target type as a function call. This makes arithmetic intent visible and prevents hard-to-find bugs.
string(65) produces the string "A" because 65 is the Unicode code point for 'A'. Use strconv.Itoa(65) or fmt.Sprintf("%d", 65) to get the string "65".
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.