Data Types in Python
Python's built-in data types include int, float, str, and bool (primitive — single values) and list, tuple, set, and dict (non-primitive — collections). Some are mutable (list, dict, set); others are immutable (int, float, str, tuple, bool).
Want to understand data types in Python? Every value you hand Python gets classified the instant you create it — a number does not sit on the same shelf as a word, and a list does not live where single values live. Those shelves are Python's data types.
This page covers the built-in types you will meet constantly — int, float, str, bool, list, tuple, dict, set — plus the two ideas that organize them: primitive vs non-primitive and mutable vs immutable. Pair it with Types, Values, and Errors for how type() works, and Variables for how names attach to these values.
What you will learn
By the end you can:
- Name Python's core built-in data types and what each one is for
- Tell primitive types (
int,float,bool,str) from non-primitive ones (list,tuple,set,dict) - Explain mutable vs immutable and why it matters
- Pick the right container: list vs tuple vs set vs dict
- Use
type()to confirm what you actually created
We are not covering type casting (
int(),str()conversions) or custom classes yet — those get their own pages. This is the map of what Python ships with by default.
Why data types exist
Python needs to know three things about every value: what operations are allowed on it, how much memory to use, and how it should behave. The same symbol can mean different things depending on type — + adds numbers but joins strings.
Numbers: values that can be calculated
Integers — whole and steady
count = 10
temperature = -5
print(type(count))
# <class 'int'>No decimals, no fractions. Python calls these integers.
Floating-point numbers — numbers that slide
pi = 3.14159
gravity = 9.8
print(type(pi))
# <class 'float'>Numbers with decimal points are stored using floating-point representation.
Strings: values that speak
name = "ada"
print(type(name))
# <class 'str'>Quotes matter — without them, Python assumes you are naming a variable. Strings can contain letters, numbers, symbols, and even spaces, but Python treats all of it as text, not math.
Booleans: yes or no, nothing else
is_active = True
is_logged_in = False
print(type(is_active))
# <class 'bool'>Booleans have exactly two possible values. They quietly power decisions, conditions, and logic everywhere in a program.
Lists: many things, one name
marks = [85, 90, 78]
names = ["Alice", "Bob", "Charlie"]
print(type(marks))
# <class 'list'>A list groups values under one name. Lists can hold multiple values, mix data types, and be changed after creation.
Tuples: lists that don't change
coordinates = (10, 20)
print(type(coordinates))
# <class 'tuple'>Tuples look like lists but behave differently. Once created, a tuple cannot be modified — use them when safety and consistency matter.
Dictionaries: meaning over position
student = {
"name": "Ravi",
"age": 20,
"branch": "CSE"
}
print(type(student))
# <class 'dict'>A dictionary stores key–value pairs. You do not ask where a value lives — you ask what it is called.
Sets: uniqueness matters
unique_ids = {101, 102, 103}
print(type(unique_ids))
# <class 'set'>A set is a collection of unique values — duplicates are automatically removed. Sets are useful when presence matters more than order.
Python never forgets what type a value is, no matter how you inspect it:
print(type(42)) # <class 'int'>
print(type("42")) # <class 'str'>
print(type([42])) # <class 'list'>Primitive vs non-primitive data types
Some values are simple. Some values are built from other values. That is the difference between primitive and non-primitive data types.
Primitive types — the building blocks
Primitive types represent one clear, atomic idea:
int— whole numbersfloat— decimal numbersbool— True or Falsestr— text (internally complex, but behaves like a single value)
age = 20
price = 99.99
is_student = True
name = "Aditya"Each variable here refers to one single value — you do not logically break it into smaller meaningful parts.
Non-primitive types — collections and structures
Non-primitive types are built from multiple values: they can store many elements, organize data, and represent more complex structures. Common ones: list, tuple, set, dict.
marks = [85, 90, 78]
coordinates = (10, 20)
unique_ids = {101, 102, 103}
student = {"name": "Ravi", "age": 20}| Primitive | Non-Primitive |
|---|---|
| Stores a single value | Stores multiple values |
| Simple data | Structured data |
| int, float, bool, str | list, tuple, set, dict |
Mutable vs immutable — what can change
Python has two kinds of values: flexible ones, and ones fixed once created.
Immutable (non-mutable)
Imagine carving something in stone — once written, you cannot edit it; to get something different, you carve a new stone. An immutable value cannot be changed after creation. Any "modification" actually creates a new object.
intfloatboolstrtuple
Mutable
Now imagine writing with a pencil — you can erase, add, and modify the same page repeatedly. A mutable value can change after creation without becoming a new object.
listdictset
Immutable objects protect stability. Mutable objects allow flexibility. Good programming means knowing which one a situation needs.
Quick reference: all built-in types at a glance
| Type | Primitive? | Mutable? | Ordered? | Duplicates? | Example |
|---|---|---|---|---|---|
| int | Primitive | No | — | — | 10 |
| float | Primitive | No | — | — | 3.14 |
| bool | Primitive | No | — | — | True |
| str | Primitive* | No | Yes | Yes | "Hello" |
| list | Non-Primitive | Yes | Yes | Yes | [1, 2, 3] |
| tuple | Non-Primitive | No | Yes | Yes | (1, 2, 3) |
| set | Non-Primitive | Yes | No | No | {1, 2, 3} |
| dict | Non-Primitive | Yes | Yes (keys 3.7+) | Keys: No, Values: Yes | {"a": 1} |
Common mistakes
- Forgetting quotes and accidentally naming a variable instead of writing a string
- Expecting a tuple to accept item reassignment like a list
- Assuming dict key order does not matter for equality or display
- Using a list when a set would remove needed duplicate-checking work
- Confusing
str's immutability with lists being similarly protected
Why this matters
Every bug involving "wrong" behavior traces back to a type you did not expect. Knowing the shelf a value sits on — primitive or structured, mutable or fixed — is what lets you predict how your program will behave before you run it.
Common questions
What are the main data types in Python?
Python's core built-in types are int, float, str, and bool (primitive types holding single values), plus list, tuple, set, and dict (non-primitive types that hold collections of values).
What is the difference between primitive and non-primitive data types in Python?
Primitive types (int, float, bool, str) store a single value. Non-primitive types (list, tuple, set, dict) are built from multiple values and organize data into structures.
What is the difference between mutable and immutable data types in Python?
Mutable types (list, dict, set) can be changed in place after creation. Immutable types (int, float, bool, str, tuple) cannot be changed — any modification creates a new object.
Is a string mutable or immutable in Python?
A string is immutable. Once created, its characters cannot be changed in place; operations like concatenation produce a new string object.
What is the difference between a list and a tuple in Python?
A list is mutable — you can add, remove, or change items after creation. A tuple is immutable — once created, its contents cannot change. Both are ordered and allow duplicates.
How do you check the data type of a value in Python?
Use the built-in type() function, for example type(42) returns
and type("42") returns .
Explore
Related topics
Keep going — these sit next to this concept in a real learning path.
Types, Values, and Errors in Python
How type() works and what values and types mean.
Variables in Python
Names that point at the data types on this page.
Operators and Operands in Python
How operators behave differently across types.
Order of Operations in Python
Precedence rules for combining numeric types.
Interactive Mode vs Script Mode in Python
Why the same line of code behaves differently in each mode.
The input() Function in Python
Reading user input and converting it from a string to a number.
Strings in Python
Indexing, slicing, immutability, and string methods.
Lists in Python
Mutability, list methods, map/filter/reduce, and the aliasing trap.
Dictionaries in Python
Key-value pairs, the histogram pattern, and memoization.
Tuples in Python
Immutability, unpacking, *args, zip(), and DSU sorting.
Sets in Python
Uniqueness, fast membership checks, and set math.
Type Casting in Python
Implicit vs explicit conversion between data types.
Functions in Python: Definition and How They Work
What functions are, def, parameters, and local scope.
Python course hub
All free Python explainers and the path into Agentic practice.