Python Data Types - Beginner's Guide
## 1. Introduction
Python has various **data types** that define the kind of values that variables can hold.
Understanding data types is crucial for writing efficient and error-free programs.
## 2. Fundamental Data Types in Python
Python has the following **built-in** data types:
- Numeric Types: `int`, `float`, `complex`
- Sequence Types: `list`, `tuple`, `range`
- Text Type: `str`
- Set Types: `set`, `frozenset`
- Mapping Type: `dict`
- Boolean Type: `bool`
- Binary Types: `bytes`, `bytearray`, `memoryview`
- None Type: `NoneType`
### 2.1 Integer (`int`)
- Stores whole numbers (positive, negative, or zero).
- Memory consumption: **28 bytes** (base size, increases dynamically as number size increases).
#### Example Usage:
```python
num1 = 100 # Positive integer
num2 = -25 # Negative integer
num3 = 0 # Zero
print(type(num1)) # Output: <class 'int'>
```
#### Additional Examples:
```python
# Performing arithmetic operations
sum_value = 5 + 10 # Addition
product = 5 * 3 # Multiplication
power = 2 ** 3 # Exponentiation
print(sum_value, product, power)
```
#### Memory Consumption Example:
```python
import sys
x = 10 # Small integer
y = 1000000000000000000 # Large integer
print(sys.getsizeof(x)) # Output: 28 bytes
print(sys.getsizeof(y)) # Output: More than 28 bytes, grows dynamically
```
#### Use Case:
- Counting items
- Representing IDs
- Performing arithmetic operations
... (Other data types are also included similarly)