1. Introduction to Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP) is a programming paradigm based on objects.
- Objects contain:
- Data (values)
- Code (functions that operate on the data)
Key Point:
OOP organizes code by combining data and behavior into objects
2. What is an Object?
An object is an instance of a class.
Examples of objects in Python:
- Strings
- Lists
- Functions
Example idea:
"hello"→ string object[1, 2, 3]→ list object
Key Point:
Everything in Python is an object
3. What is a Class?
A class is a blueprint or data type for creating objects.
- Defines:
- What data an object holds
- What actions it can perform
Example:
"hocus pocus"→ instance of string class
Key Point:
Class = template, Object = actual instance
4. Why Classes Are Useful
Classes allow:
- Organized code
- Reusable functionality
- Built-in tools attached to data
Key Point:
Data + functions are bundled together
5. Methods (Actions)
A method is a function that belongs to a class.
- Performs an action on an object
- Uses parentheses
()
Examples (String Methods):
.swapcase()→ changes uppercase ↔ lowercase.replace()→ replaces characters.split()→ splits string into list
Key Point:
Methods modify or act on object data
6. Dot Notation
Dot notation is used to access methods and attributes.
Structure:
object.method()object.attribute
Example:
magic.swapcase()
Key Point:
Dot notation connects object → its functionality
7. Discovering Methods
You do NOT need to memorize methods.
- In environments like Jupyter Notebook:
- Type
.and press Tab - See available methods
- Type
Key Point:
Use tools to explore available functionality
8. Core Python Classes (Built-in Types)
Common built-in classes include:
- Integers (
int) - Floats (
float) - Strings (
str) - Booleans (
bool) - Lists (
list) - Dictionaries (
dict) - Tuples (
tuple) - Sets (
set) - Functions
- Range
- None (empty value)
Key Point:
These are fundamental building blocks in Python
9. Attributes (Properties)
An attribute is a value associated with an object.
- Accessed using dot notation
- Does NOT use parentheses
Example:
- DataFrame attribute:
.shape→ returns dimensions.columns→ returns column names
Key Point:
Attributes describe an object, not change it
10. Methods vs Attributes
| Concept | Purpose | Syntax |
|---|---|---|
| Method | Performs an action | () required |
| Attribute | Describes object property | No () |
Key Point:
Methods = action, Attributes = information
11. OOP in Data Analysis
OOP is powerful for data analysis because:
- Data and operations are grouped together
- Code becomes:
- Cleaner
- More reusable
- Easier to manage
Example:
- DataFrame object:
- Contains data
- Has methods to analyze it
- Has attributes to describe it
Key Point:
OOP makes complex data workflows manageable
12. Custom Classes
- Python allows you to:
- Create your own classes
- Extend functionality
- Libraries also provide custom classes
Key Point:
Python is highly extensible
Final Summary
Object-Oriented Programming (OOP) is a system that structures code around objects, which combine data and functionality. Classes define the structure of objects, while methods allow actions and attributes provide information. Using dot notation, you can access both methods and attributes. This approach makes Python code more organized, reusable, and powerful—especially for data analysis tasks.
Key Takeaways
- Everything in Python is an object
- Class = blueprint, Object = instance
- Methods perform actions (
()) - Attributes store information (no
()) - Dot notation connects object to its features
- OOP improves organization and reusability
- Essential for working with data structures like DataFrames
