Data Type
Table of Contents
A classification specifying what kind of value a variable can hold, what operations are valid on it, and how much memory to allocate. The foundation of a language's Type System — type checking (at compile time or runtime) prevents operations being applied to incompatible data.
Related: Type System Data Structures
Categories
Primitive Types
Built into the language — no construction required.
| Kind | Examples |
|---|---|
| Integer | int (Python), i32 (Rust), int (C#), number (JS) |
| Float | float (Python), f64 (Rust), double (C#) |
| Boolean | bool — true / false |
| Character | char (Rust, C#, Java) — single character or Unicode scalar |
| String | Primitive in Python/JS; heap-allocated object in Rust/C# |
| Null/None | None (Python), null (JS/C#), () unit type (Rust) |
Composite / Compound Types
Built from primitives — aggregate multiple values.
| Kind | Examples |
|---|---|
| Array / List | Fixed or dynamic sequence of same type |
| Tuple | Fixed sequence of mixed types |
| Struct / Record | Named fields of mixed types |
| Enum | One of a fixed set of variants |
| Map / Dict | Key-value pairs |
| Set | Unique values |
Type System Properties
| Property | Meaning | Examples |
|---|---|---|
| Static | Types checked at compile time | Rust, C#, Java |
| Dynamic | Types checked at runtime | Python, JavaScript |
| Strong | No implicit coercion between incompatible types | Rust, Python |
| Weak | Implicit coercion permitted | JavaScript, C |
Python is dynamically typed but strongly typed — 1 + "2" is a
runtime error, not silent coercion. JavaScript is weakly typed —
1 + "2" produces "12".
Language Examples
# Python — dynamic, strong x = 42 # int inferred x = "hello" # reassignment to different type is allowed x + 1 # TypeError at runtime — no implicit coercion
// Rust — static, strong let x: i32 = 42; let y: f64 = 3.14; // let z = x + y; // compile error — mismatched types let z = x as f64 + y; // explicit cast required
// C# — static, strong int count = 42; string label = "items"; // var result = count + label; // compile error var result = count.ToString() + label; // explicit conversion
Tips
- Type errors caught at compile time (static typing) are cheaper to fix than those caught at runtime (dynamic typing) — they surface immediately and with precise location information
- "Strongly typed" and "statically typed" are often conflated but are independent properties — Python is strong/dynamic, C is weak/static
- In Rust, the absence of null as a value (replaced by
Option<T>) eliminates an entire category of null pointer errors at the type level — see Rust Type System