Python Data Types Explained – Simple Guide for Everyone
Python automatically figures out what kind of data you're working with — so you don't have to declare variable types. This makes Python both powerful and beginner-friendly.
What Is a Data Type?
A data type describes the kind of data a variable stores, such as numbers, text, true/false, and collections like lists or dictionaries.
For example:
a = 5
→ this is an integer
name = "Alice"
→ this is text (string)
1. Numeric Types
- int: whole numbers (e.g. 5, 0, -10)
- float: numbers with decimals (e.g. 3.14)
- complex: special numbers (e.g. 1 + 2j)
print(type(5)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type(1+2j)) # <class 'complex'>
2. Text Type – str
Strings store words or sentences, surrounded by quotes:
message = "Hello, World!"
print(message)
Great for text input, messages, file paths, etc.
3. Boolean Type – bool
These are True
or False
values — ideal for decisions:
is_raining = False
print(5 > 3) # True
4. Sequence Types
List – changeable collection
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)
Tuple – fixed collection
point = (10, 20)
print(point[0]) # 10
Range – sequence of numbers
for i in range(3):
print(i) # 0, 1, 2
When to use? Use lists when you need to change items, tuples when data should stay the same, and range for loops.
5. Dictionaries – dict
Store information in pairs: key → value.
person = {"name": "Bob", "age": 25}
print(person["name"]) # Bob
Good for configuration or structured data like JSON.
6. Sets – set
& frozenset
Sets hold unique items:
nums = {1, 2, 3, 2}
print(nums) # {1, 2, 3}
A frozenset
is like a frozen version (cannot change once created).
7. NoneType – None
Represents no value or missing data:
answer = None
if answer is None:
print("Not answered yet")
Data Type Summary
Type | Example | Changeable? | Use |
---|---|---|---|
int | 42 | No | Counting, IDs |
float | 3.14 | No | Measurements |
complex | 1 + 2j | No | Science/math |
str | "Hello" | No | Text data |
bool | True/False | No | Logic checks |
list | [1,2,3] | Yes | Changeable list |
tuple | (1,2,3) | No | Fixed list |
range | range(5) | No | Loops |
dict | {"x":1} | Yes | Key-value pairs |
set | {1,2,3} | Yes | Unique items |
frozenset | frozenset(...) | No | Immutable set |
NoneType | None | No | Missing value |
✅ Final Thoughts
Learning Python’s data types — like number, text, list, and dictionary — is key to writing clear, efficient code. Python does the hard work by figuring out types automatically, but knowing what each type can do gives you more control and confidence.
Watch this video to see all data types in action: