Unit II
Primary data types:
Python is a dynamically-typed, high-level programming language widely used in data
science and statistics. Understanding Python's data types is essential for efficient data
handling, preprocessing, statistical computation, and machine learning model building.
1. Numeric Types: Used to store numerical values.
int: Integer numbers (e.g., 5, -3, 200). Used in counting, categorical encoding,
indexing. Example: x = 10 (age count, frequency count).
float: Floating-point numbers (e.g., 3.14, -2.0, 1.0e-5). Essential for representing
continuous values such as probabilities, measurements.
Example: pi = 3.1416 (probability, measurement).
complex: Numbers with real and imaginary parts. Useful in advanced scientific
computation. Example: z = 2 + 3j (signal processing, advanced statistical algorithms).
2. Sequence Types
str: String type, stores textual data (e.g., 'data', "model"), useful in handling
categorical variables, metadata, file I/O. Example: name = "Python" (labels,
category names).
list: Mutable ordered collection (e.g., [1, 2,erogeneous element storage (mix of
numbers, strings). Used in data aggregation, transforms. Example: scores = (marks
for students).
tuple: Immutable ordered collection (e.g., (3.1, 2.4)), often used for fixed datasets like
coordinates, function returns. Example: point = (3.5, 4.2) (coordinates, fixed pairs).
range: Represents arithmetic progressions, mainly for iteration control. Example: r =
range(1, 6) → 1, 2, 3, 4, 5.
3. Mapping Type
dict: Dictionary type; stores key-value pairs. Crucial for fast data lookup, mapping
feature names to values.
4. Set Types
set: Unordered collection of unique elements. Used for statistical set operations,
deduplication.
frozenset: Immutable version of a set, can be used as dictionary keys when needed.
5. Boolean Type
bool: True or False. Fundamental in conditional statements, binary classification
tasks.
6. Binary Types
bytes: Immutable sequence of bytes, useful in file handling, image or network data.
bytearray: Mutable byte sequence, allows editing of binary data.
memoryview: Accesses memory of binary objects without copying data.
7. NoneType