Nearby lessons
27 of 108Python 3 - Data Types Summary
Introduction
Python provides several built-in data types to store different kinds of data.
Each data type has its own purpose and characteristics.
Some data types are immutable, while others are mutable.
Summary of Python Data Types
| Data Type | Description | Mutable / Immutable |
|---|---|---|
int |
Stores whole numbers. | Immutable |
float |
Stores decimal numbers. | Immutable |
complex |
Stores complex numbers. | Immutable |
bool |
Stores True or False. |
Immutable |
str |
Stores text (sequence of characters). | Immutable |
bytes |
Stores byte values (0 to 255). | Immutable |
bytearray |
Stores byte values (0 to 255). | Mutable |
range |
Represents a sequence of numbers. | Immutable |
list |
Stores an ordered collection of objects. | Mutable |
tuple |
Stores an ordered collection of objects. | Immutable |
set |
Stores an unordered collection of unique values. | Mutable |
frozenset |
Immutable version of a set. | Immutable |
dict |
Stores data as key-value pairs. | Mutable |
None |
Represents no value or nothing. | Immutable |
Examples of All Data Types
The following examples show how each data type is created in Python.
Example - int
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - float
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - complex
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
10.0 5.0
Example - bool
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - str
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - bytes
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - bytearray
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - range
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - list
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - tuple
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - set
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - frozenset
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - dict
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Example - None
🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
No output captured.
Mutable and Immutable Data Types
| Immutable Data Types | Mutable Data Types |
|---|---|
| int | bytearray |
| float | list |
| complex | set |
| bool | dict |
| str | - |
| bytes | - |
| range | - |
| tuple | - |
| frozenset | - |
| None | - |
Important Notes
- Python provides several built-in data types for different kinds of data.
- Choose the correct data type based on your requirement.
- Immutable objects cannot be modified after creation.
- Mutable objects can be modified after creation.
- Understanding data types is the foundation of Python programming.
Quick Summary
| Data Type | Purpose | Mutable? |
|---|---|---|
| int | Whole numbers | No |
| float | Decimal numbers | No |
| complex | Complex numbers | No |
| bool | True / False | No |
| str | Text | No |
| bytes | Byte values | No |
| bytearray | Mutable byte values | Yes |
| range | Number sequence | No |
| list | Ordered collection | Yes |
| tuple | Read-only collection | No |
| set | Unique values | Yes |
| frozenset | Read-only set | No |
| dict | Key-value pairs | Yes |
| None | No value | No |
🧠 Test Your Knowledge
8 QuestionsProgress: 0 / 8
Keep Going!Python - Escape Characters