Go Data Types
Go is statically typed, meaning every variable has a specific type determined at compile time.
1. Variables
There are two main ways to declare variables:
2. Basic Types
- Integers:
int,int8,int64,uint(unsigned). Usually, just useint. - Floats:
float32,float64. Usually, just usefloat64. - Booleans:
bool(trueorfalse). - Strings:
string(UTF-8 encoded).
3. Zero Values
Variables declared without an explicit initial value are given their zero value:
0for numeric types.falsefor booleans.""(empty string) for strings.
4. Constants
Constants are values that cannot be changed once declared.
Constants are declared in capital letters.
5. Type Conversions
Go never performs implicit conversions (e.g., you can't add an int to a float64). You must be explicit.
6. Strings and Immutability
Strings in Go are immutable. You cannot change a single character in a string. Instead, you create a new string.