🐍 Python Built-in Data Types
Python has several built-in data types grouped into categories:
📦 Basic Types
| Type |
Description |
Example |
int |
Integer numbers |
x = 10 |
float |
Floating-point numbers |
pi = 3.14 |
complex |
Complex numbers |
z = 2 + 3j |
bool |
Boolean values (True or False) |
is_valid = True |
str |
Text (string) |
name = "Alice" |
NoneType |
Represents the absence of a value |
x = None |
📚 Sequence Types
| Type |
Description |
Example |
list |
Ordered, mutable sequence |
fruits = ["apple", "banana"] |
tuple |
Ordered, immutable sequence |
point = (1, 2) |
range |
Sequence of numbers (typically for loops) |
range(5) → 0,1,2,3,4
|
🔑 Mapping Type
| Type |
Description |
Example |
dict |
Key-value pairs |
user = {"name": "Alice", "age": 30} |
🔢 Set Types
| Type |
Description |
Example |
set |
Unordered, unique items |
colors = {"red", "blue"} |
frozenset |
Immutable set |
fs = frozenset([1, 2, 3]) |
🧵 Binary Types
| Type |
Description |
Example |
bytes |
Immutable sequence of bytes |
b = b"hello" |
bytearray |
Mutable sequence of bytes |
ba = bytearray(b"hello") |
memoryview |
Memory view of a byte object |
mv = memoryview(b"hello") |
🛠️ Type Checking
type(42) # <class 'int'>
isinstance("hi", str) # True
🧠 Tip
Use type() to inspect a value’s type, and isinstance() to check if a value matches a certain type.
Top comments (0)