Python Data Types
🧱 Python Data Types
Data types define the kind of value stored in a variable. Python is dynamically typed, meaning you don’t need to declare a type—the interpreter detects it automatically.
Example:
🔍 How to Check Data Type
Use the type() function:
🏷 Categories of Python Data Types
| Category | Data Type |
|---|---|
| Text | str (String) |
| Numeric | int, float, complex |
| Boolean | bool |
| Sequence | list, tuple, range |
| Mapping | dict |
| Set | set, frozenset |
| Binary | bytes, bytearray, memoryview |
| None Type | NoneType |
📌 Python Built-in Data Types Explained
1️⃣ String (str)
Used for text data.
Strings can be in single ' ', double " ", or triple quotes """ """.
2️⃣ Numeric Types
🔹 int (Integer)
Whole numbers:
🔹 float (Decimal Numbers)
🔹 complex (Numbers with imaginary part)
3️⃣ Boolean (bool)
Stores True or False.
4️⃣ List (list)
Ordered, changeable, allows duplicates.
5️⃣ Tuple (tuple)
Ordered, unchangeable, allows duplicates.
6️⃣ Range (range)
Used in loops.
7️⃣ Dictionary (dict)
Stores data in key: value pairs.
8️⃣ Set (set)
Unordered, no duplicate items.
9️⃣ Frozen Set (frozenset)
Immutable (unchangeable) version of set.
🔟 Binary Types
| Type | Description |
|---|---|
bytes |
Immutable binary data |
bytearray |
Mutable binary data |
memoryview |
Access memory of binary objects |
Example:
1️⃣1️⃣ None Type (NoneType)
Represents empty or no value.
🧪 Example Program Using All Types
🏁 Summary Table
| Data Type | Example |
|---|---|
str |
"Hello" |
int |
10 |
float |
10.5 |
bool |
True |
list |
[1,2,3] |
tuple |
(1,2,3) |
dict |
{"a":1} |
set |
{1,2,3} |
complex |
3+5j |
NoneType |
None |
🧠 Practice Tasks
Try these:
-
Create a variable of each data type and print its type.
-
Convert integer to float and float to integer.
-
Create a list and modify one value.
-
Create a tuple and try modifying it — notice the error.
