Nearby lessons
23 of 159Python - Data Types Summary
📌 What You Will Learn
- Identify the built-in data types available in Python
- Explain the purpose of each built-in data type
- Distinguish mutable data types from immutable data types
- Run examples that create values of every data type
- Use the type() function to check the data type of a value
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
Example - float
Example - complex
Example - bool
Example - str
Example - bytes
Example - bytearray
Example - range
Example - list
Example - tuple
Example - set
Example - frozenset
Example - dict
Example - None
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 |
📝 Key Takeaways
- Python provides several built-in data types for storing different kinds of data
- int, float, complex, bool, str, bytes, range, tuple, frozenset, and None are immutable
- list, bytearray, set, and dict are mutable data types
- The type() function returns the class of a value
- Each data type has its own purpose and characteristics
🧠 Test Your Knowledge
8 QuestionsProgress: 0 / 8