Skip to main content

OPPS

 

Module 1: Introduction to Object-Oriented Programming

  • Procedural vs Object-Oriented Programming

  • Key concepts of OOP (Encapsulation, Abstraction, Inheritance, Polymorphism)

  • Python as an Object-Oriented Language

  • Classes and Objects

1. Procedural vs Object-Oriented Programming

Procedural Programming

  • Focuses on functions (procedures) that operate on data.

  • Code is written as a sequence of instructions.

  • Uses global variables and functions to modify data.

  • Example languages: C, Pascal, BASIC

Object-Oriented Programming (OOP)

  • Focuses on objects that contain both data and functions (methods).

  • Encapsulates data inside objects to improve security.

  • Uses classes to define blueprints for objects.

  • Example languages: Python, Java, C++

Example: Procedural vs OOP in Python

Procedural Approach:

python
# Procedural approach - Function based def student_details(name, age, marks): print(f"Student Name: {name}, Age: {age}, Marks: {marks}") # Calling the function student_details("Alice", 20, 85)

OOP Approach:

python
# Object-Oriented Approach - Class based class Student: def __init__(self, name, age, marks): self.name = name self.age = age self.marks = marks def display(self): print(f"Student Name: {self.name}, Age: {self.age}, Marks: {self.marks}") # Creating an object s1 = Student("Alice", 20, 85) s1.display()

✅ OOP groups data and functions inside a class, making code more structured, reusable, and secure.


2. Key Concepts of OOP

  1. Encapsulation: Hiding data within a class and exposing only necessary parts.

  2. Abstraction: Hiding implementation details and showing only essential features.

  3. Inheritance: One class inherits the properties of another class.

  4. Polymorphism: One function or method can work in different ways.

I will explain each concept in detail when we go deeper into OOP.


3. Python as an Object-Oriented Language

Python supports OOP fully, allowing us to:

  • Define classes and objects

  • Implement encapsulation, inheritance, and polymorphism

  • Use built-in special (dunder) methods

Example of Python’s OOP nature:

python
class Car: def __init__(self, brand, model): self.brand = brand self.model = model def show(self): print(f"Car: {self.brand} {self.model}") # Creating object c1 = Car("Toyota", "Camry") c1.show()

4. Classes and Objects

What is a Class?

  • class is a blueprint for creating objects.

  • It defines attributes (data) and methods (functions) for objects.

What is an Object?

  • An object is an instance of a class.

  • It has its own unique values for the attributes.

Example of a Class and Object in Python

python
class Animal: def __init__(self, name, species): self.name = name # Instance variable self.species = species def speak(self): print(f"{self.name} makes a sound!") # Creating objects a1 = Animal("Dog", "Mammal") a2 = Animal("Parrot", "Bird") # Calling methods a1.speak() # Output: Dog makes a sound! a2.speak() # Output: Parrot makes a sound!


1. Defining a Class

A class is a blueprint for creating objects. It defines attributes (data) and methods (functions) that objects will have.

Example: Defining a Simple Class

python
class Car: pass # Empty class (for now)

Here, Car is a class, but it doesn’t have any properties or methods yet.


2. Creating Objects

An object is an instance of a class. Once a class is defined, we can create objects from it.

Example: Creating an Object

python
class Car: def __init__(self, brand, model): self.brand = brand self.model = model # Creating objects car1 = Car("Toyota", "Camry") car2 = Car("Honda", "Civic") print(car1.brand, car1.model) # Output: Toyota Camry print(car2.brand, car2.model) # Output: Honda Civic
  • car1 and car2 are objects created from the Car class.

  • They have different values for the brand and model attributes.


3. __init__ Constructor

  • __init__ is a special method (constructor) in Python that runs automatically when an object is created.

  • It is used to initialize an object’s attributes.

Example: Using __init__ Constructor

python
class Student: def __init__(self, name, age): self.name = name # Instance variable self.age = age def display(self): print(f"Student Name: {self.name}, Age: {self.age}") # Creating objects s1 = Student("Alice", 20) s2 = Student("Bob", 22) s1.display() # Output: Student Name: Alice, Age: 20 s2.display() # Output: Student Name: Bob, Age: 22
  • __init__ assigns values to name and age when an object is created.

  • self refers to the instance of the class.


4. Class and Instance Attributes

Instance Attributes (Belong to each object)

  • Defined inside the __init__ method using self.

  • Each object gets its own copy.

Class Attributes (Belong to the class)

  • Defined outside the __init__ method.

  • Shared among all objects.

Example: Class vs Instance Attributes

python
class Employee: company = "Google" # Class attribute def __init__(self, name, salary): self.name = name # Instance attribute self.salary = salary # Creating objects e1 = Employee("Alice", 60000) e2 = Employee("Bob", 70000) print(e1.company, e1.name, e1.salary) # Google Alice 60000 print(e2.company, e2.name, e2.salary) # Google Bob 70000 # Changing class attribute Employee.company = "Microsoft" print(e1.company) # Microsoft print(e2.company) # Microsoft
  • company is a class attribute, shared among all employees.

  • name and salary are instance attributes, unique for each object.


5. Methods in a Class

  • Instance Methods → Operate on instance attributes (self).

  • Class Methods → Operate on class attributes (@classmethod).

  • Static Methods → Do not use self or cls (@staticmethod).

Example: Instance and Class Methods

python
class Employee: company = "Google" # Class attribute def __init__(self, name, salary): self.name = name self.salary = salary def display(self): # Instance method print(f"Name: {self.name}, Salary: {self.salary}") @classmethod def change_company(cls, new_name): cls.company = new_name # Changing class attribute # Creating objects e1 = Employee("Alice", 60000) e1.display() # Output: Name: Alice, Salary: 60000 print(e1.company) # Output: Google # Changing class attribute using class method Employee.change_company("Microsoft") print(e1.company) # Output: Microsoft

6. self Keyword

  • self refers to the current instance of the class.

  • It allows access to instance attributes and methods.

  • It must be the first parameter of an instance method.

Example: Understanding self

python
class Dog: def __init__(self, name, breed): self.name = name self.breed = breed def bark(self): print(f"{self.name} is barking!") dog1 = Dog("Buddy", "Labrador") dog2 = Dog("Rocky", "Bulldog") dog1.bark() # Output: Buddy is barking! dog2.bark() # Output: Rocky is barking!

Here:

  • self.name refers to the current object's name (Buddy or Rocky).

  • Each object has its own copy of name and breed.


Summary

ConceptDescription
ClassBlueprint for creating objects
ObjectAn instance of a class
__init__Constructor that initializes instance attributes
Instance AttributesAttributes unique to each object
Class AttributesAttributes shared across all objects
Instance MethodWorks with self, modifies instance attributes
Class MethodWorks with cls, modifies class attributes
self KeywordRefers to the current instance of a class

Module 2: Classes and Objects in Python

  • Defining a Class

  • Creating Objects

  • __init__ Constructor

  • Class and Instance Attributes

  • Methods in a Class

  • self keyword

Module 3: Encapsulation and Data Hiding

  • Public, Private, and Protected Members

  • Getter and Setter Methods

  • @property decorator

Encapsulation in Python (Brief Explanation)

Encapsulation is a fundamental Object-Oriented Programming (OOP) concept that hides the internal details of an object and only exposes the necessary parts to the outside world.

Key Features of Encapsulation:

Data Hiding → Prevents direct access to sensitive data.
Controlled Access → Allows modification only through specific methods.
Improves Security → Prevents unintended changes to object attributes.
Enhances Code Maintainability → Makes the code cleaner and easier to update.


Example of Encapsulation

python
class BankAccount: def __init__(self, owner, balance): self.owner = owner # Public attribute self.__balance = balance # Private attribute (Encapsulated) # Getter method to access balance def get_balance(self): return self.__balance # Setter method to update balance with validation def set_balance(self, amount): if amount < 0: print("Balance cannot be negative!") else: self.__balance = amount # Creating an object account = BankAccount("Alice", 10000) # Accessing private variable (incorrect way - gives error) # print(account.__balance) # ❌ AttributeError # Accessing private variable using getter method print(account.get_balance()) # ✅ Output: 10000 # Updating private variable using setter method account.set_balance(12000) print(account.get_balance()) # ✅ Output: 12000

Encapsulation with @property Decorator

The @property decorator allows getter and setter methods to be used like normal attributes.

python
class Employee: def __init__(self, name, salary): self.name = name self.__salary = salary # Private attribute @property def salary(self): # Getter return self.__salary @salary.setter def salary(self, amount): # Setter if amount < 0: print("Salary cannot be negative!") else: self.__salary = amount # Creating an object emp = Employee("John", 50000) # Accessing salary using property print(emp.salary) # ✅ Output: 50000 # Modifying salary using setter emp.salary = 60000 print(emp.salary) # ✅ Output: 60000 # Trying to set a negative salary emp.salary = -5000 # ❌ Output: Salary cannot be negative!

Module 4: Inheritance in Python

  • Types of Inheritance (Single, Multiple, Multilevel, Hierarchical, Hybrid)

  • Method Overriding

  • super() function

  • MRO (Method Resolution Order)

Module 5: Polymorphism

  • Method Overloading (Not directly supported in Python)

  • Method Overriding

  • Operator Overloading (__add__, __sub__, __mul__, etc.)

Module 6: Abstraction

  • Abstract Classes and Methods

  • ABC module and @abstractmethod decorator

Module 7: Special (Magic/Dunder) Methods

  • __str__, __repr__

  • __len__, __call__, __del__, etc.

  • Customizing behavior using dunder methods

Module 8: Working with Class and Static Methods

  • @classmethod and @staticmethod

  • Difference between instance, class, and static methods

Module 9: Exception Handling in OOP

  • Using try, except, finally in OOP

  • Creating Custom Exceptions (User-Defined Exceptions)

Module 10: File Handling and OOP

  • Reading/Writing Files in an OOP Way

  • Creating a File Handler Class

Module 11: OOP Design Principles

  • SOLID Principles

  • DRY (Don't Repeat Yourself)

  • Object-Oriented Design Patterns (Factory, Singleton, etc.)

Module 12: Mini Project

  • Building a small project using OOP in Python (Library Management System, Bank Account System, etc.)

Comments

Popular posts from this blog

Decision Tree Algorithm

  Decision Tree Algorithm The ID3 (Iterative Dichotomiser 3) algorithm is a Decision Tree classification algorithm that selects attributes based on Information Gain (IG) to maximize data purity at each step. Step 1: Understanding the Key Concepts Before implementing ID3, let's understand the core concepts: 1. Entropy (H) Entropy measures the impurity or uncertainty in the dataset: If all samples belong to one class , entropy = 0 (pure dataset). If the dataset is evenly split between classes, entropy = 1 (most uncertain). Formula for Entropy: H ( S ) = − ∑ p i log ⁡ 2 ( p i ) H(S) = - \sum p_i \log_2(p_i) H ( S ) = − ∑ p i ​ lo g 2 ​ ( p i ​ ) Where: p i p_i p i ​ = Probability of class i i i in dataset S S S log ⁡ 2 \log_2 lo g 2 ​ = Logarithm base 2 2. Information Gain (IG) Information Gain tells us how much entropy is reduced after splitting the data using an attribute. Formula for Information Gain: I G ( S , A ) = H ( S ) − H ( S ∣ A ) IG(S,A) = H(S)...

OPRATING SYSTEM

 https://drive.google.com/drive/folders/1VAYZuJLVeDBUd1UM2C4nvJTysqB3fMmt 📌 Module 1: Operating System Fundamentals 1️⃣ Introduction to Operating System & Evolution What is an Operating System (OS)? An Operating System (OS) is system software that acts as an interface between hardware and users , managing system resources efficiently. Key Functions of an OS ✅ Process Management – Controls execution of programs ✅ Memory Management – Allocates memory to processes ✅ File System Management – Manages files and directories ✅ Device Management – Controls hardware devices ✅ Security & Access Control – Protects data and system resources 2️⃣ Evolution of Operating Systems Era OS Type Example Characteristics 1950s Batch OS IBM Mainframes Executes jobs sequentially 1960s Multiprogramming OS UNIX Runs multiple processes simultaneously 1970s Time-Sharing OS MULTICS CPU switches between multiple users 1980s Personal Computing OS MS-DOS, Mac OS Single-user OS for PCs 199...

sql

  📌 Module 1: Introduction to SQL 🔹 What is SQL? 🔹 Database vs. DBMS vs. RDBMS 🔹 Types of Databases (SQL vs. NoSQL) 🔹 Popular SQL Databases (MySQL, PostgreSQL, SQLite, Oracle, MS SQL Server) 🔹 Installing MySQL/PostgreSQL & Setting Up Database ✅ Hands-on: ✔️ Install MySQL/PostgreSQL & Set Up a Test Database 📌 Module 2: SQL Basics - Data Retrieval 🔹 Understanding Database Tables & Schemas 🔹 SELECT Statement – Retrieving Data 🔹 Using WHERE Clause for Filtering 🔹 ORDER BY for Sorting Results 🔹 Using LIMIT & OFFSET for Pagination ✅ Hands-on: ✔️ Retrieve Employee Details from a Database 📌 Module 3: SQL Functions & Aggregation 🔹 Built-in Functions ( COUNT() , SUM() , AVG() , MIN() , MAX() ) 🔹 Using GROUP BY for Aggregation 🔹 HAVING Clause for Filtering Groups 🔹 Using DISTINCT for Unique Values ✅ Hands-on: ✔️ Find Total Salary, Average Salary, and Count of Employees per Department 📌 Module 4: SQL Joins & Relationsh...