🐍 Python Data Types – From Basics to Pro (Step-by-Step)
Here's Python data types covered in a crisp, step-by-step beginner-to-pro tutorial. This article addresses all the fundamental types, how they are treated by Python, and practical examples you can experiment with.
Written By: Nivesh Bansal Linkedin, GitHub, Instagram
📄 What are Data Types?
Each value in Python has a data type. It informs Python about the type of value stored in a variable — a number, string, list, etc.
You don't have to explicitly define data types. Python infers them for you!
x = 5 # int
y = 3.14 # float
name = "Nivesh" # str
📊 Built-in Data Types in Python
Python supports various built-in data types:
| Category | Data Types |
|---|---|
| Text Type | str |
| Numeric Types |
int, float, complex
|
| Sequence Types |
list, tuple, range
|
| Mapping Type | dict |
| Set Types |
set, frozenset
|
| Boolean Type | bool |
| Binary Types |
bytes, bytearray, memoryview
|
🔢 Numeric Types
int - Whole numbers
age = 25
float - Decimal numbers
pi = 3.1415
complex - Complex numbers (used in advanced math)
z = 3 + 2j
🔍 Text Type: str
Used for strings (text):
greeting = "Hello, world!"
📆 Boolean Type: bool
Represents True or False:
is_active = True
is_logged_in = False
📂 Sequence Types
list - Ordered, mutable collection
colors = ["red", "blue", "green"]
tuple - Ordered, immutable collection
coordinates = (10, 20)
range - Sequence of numbers
nums = range(1, 6) # 1 to 5
📝 Mapping Type: dict
A collection of key-value pairs:
person = {
"name": "Radha",
"age": 22
}
✨ Set Types
set - Unique, unordered elements
unique_nums = {1, 2, 3, 2}
frozenset - Immutable set
frozen = frozenset(["a", "b"])
🚫 Type Checking
Use type() to determine a variable's type:
x = 5
print(type(x)) # <class 'int'>
⚖️ Type Conversion
Convert from one type to another using built-in functions:
x = 10
print(float(x)) # 10.0
-
int("5")➞ 5 -
str(10)➞ "10" -
list("abc")➞ ["a", "b", "c"]
💞 Bonus Tip: Duck Typing
Python has duck typing: “If it walks like a duck and quacks like a duck, it’s a duck.”
You only need to care about the type when it matters.
📚 Keep learning, and happy coding!
Written By: Nivesh Bansal Linkedin, GitHub, Instagram




Very helpful!