Showing posts with label Paper- 2 Object Oriented Programming & Python Basics. Show all posts
Showing posts with label Paper- 2 Object Oriented Programming & Python Basics. Show all posts

Friday, December 26, 2025

📘 PAPER 2: OBJECT ORIENTED PROGRAMMING WITH PYTHON UNIT 5 – NumPy and Pandas (university of allahabad)

 

🔴 UNIT 5 – NumPy and Pandas


🟦 PART A: NUMPY (Numerical Python)


1️⃣ Introduction to NumPy

✅ What is NumPy?

NumPy is a Python library used for:

  • Numerical computation

  • Scientific computing

  • Working with arrays and matrices

✅ Features of NumPy

✔ Faster than Python lists
✔ Supports multi-dimensional arrays
✔ Efficient memory usage
✔ Used in ML, AI, Data Science


2️⃣ ndarray (N-Dimensional Array)

Definition:

The main object of NumPy is ndarray, which represents a multi-dimensional array.

Example:

import numpy as np a = np.array([1,2,3]) print(a)

3️⃣ Data Types in NumPy

a = np.array([1,2,3], dtype=float)

Common Data Types:

  • int

  • float

  • bool

  • complex


4️⃣ Array Attributes

AttributeDescription
ndimNumber of dimensions
shapeSize of array
sizeTotal elements
dtypeData type

Example:

a = np.array([[1,2],[3,4]]) print(a.ndim) print(a.shape)

5️⃣ Array Creation Routines

🔹 From List

np.array([1,2,3])

🔹 Zeros & Ones

np.zeros((2,2)) np.ones((3,3))

🔹 Using arange()

np.arange(1,10,2)

🔹 Using linspace()

np.linspace(1,10,5)

6️⃣ Array from Existing Data

np.asarray([1,2,3]) np.frombuffer(b'hello', dtype='S1')

7️⃣ Array Indexing & Slicing

a = np.array([10,20,30,40]) print(a[1]) print(a[1:3])

8️⃣ Mathematical Operations

a + b a * b np.sqrt(a) np.sum(a) np.mean(a)

🟩 PART B: PANDAS


9️⃣ Introduction to Pandas

✅ What is Pandas?

Pandas is a Python library used for:

  • Data analysis

  • Data manipulation

  • Handling structured data


🔟 Pandas Data Structures

1️⃣ Series

A one-dimensional labeled array.

import pandas as pd s = pd.Series([10,20,30])

2️⃣ DataFrame

A two-dimensional table-like structure.

data = { "Name": ["Amit", "Rahul"], "Marks": [80, 90] } df = pd.DataFrame(data)

1️⃣1️⃣ Creating Series

From List

pd.Series([1,2,3])

From Dictionary

pd.Series({'a':10, 'b':20})

From Scalar

pd.Series(5, index=[1,2,3])

1️⃣2️⃣ Creating DataFrame

From List

pd.DataFrame([[1,2],[3,4]])

From Dictionary

pd.DataFrame({ "Name":["A","B"], "Age":[20,22] })

1️⃣3️⃣ Manipulating DataFrames

Rename Column

df.rename(columns={"Name":"Student_Name"})

Delete Column

df.drop("Age", axis=1)

Delete Row

df.drop(0)

1️⃣4️⃣ Handling Missing Values

Finding Missing Values

df.isnull()

Filling Missing Values

df.fillna(0)

Dropping Missing Values

df.dropna()

1️⃣5️⃣ Advantages of Pandas

✔ Easy data handling
✔ Fast processing
✔ Data cleaning
✔ Used in ML & AI

📘 PAPER 2: OBJECT ORIENTED PROGRAMMING WITH PYTHON UNIT 4 – Dictionaries, Functions, File Handling & Regular Expressions (university of allahabad)

 

🔴 UNIT 4 – Dictionaries, Functions, File Handling & Regular Expressions


1️⃣ Dictionaries in Python

✅ Definition

A dictionary is an unordered collection of data stored as key–value pairs.

Example:

student = { "name": "Amit", "age": 20, "course": "MCA" }

🔹 Characteristics

✔ Key-value based
Mutable
Keys must be unique
Fast access


🔹 Accessing Dictionary Elements

print(student["name"])

🔹 Adding & Updating Values

student["age"] = 21 student["city"] = "Delhi"

🔹 Deleting Elements

del student["age"]

2️⃣ Counting Frequency Using Dictionary

Example:

text = "banana" freq = {} for ch in text: if ch in freq: freq[ch] += 1 else: freq[ch] = 1 print(freq)

Output:

{'b':1, 'a':3, 'n':2}

3️⃣ Python Functions

✅ Definition

A function is a block of reusable code.


🔹 Function Syntax

def function_name(parameters): statements return value

🔹 Types of Arguments

  1. Positional

  2. Keyword

  3. Default

  4. Variable-length


Example:

def add(a, b=5): return a + b

4️⃣ Passing Function as Argument

def square(x): return x*x def fun(f, value): return f(value) print(fun(square, 5))

5️⃣ Lambda Function

Definition:

Anonymous function written in one line.

square = lambda x: x*x print(square(5))

6️⃣ Map Function

nums = [1,2,3] result = list(map(lambda x: x*2, nums))

7️⃣ List Comprehension

squares = [x*x for x in range(5)]

8️⃣ File Handling in Python


🔹 Opening a File

f = open("data.txt", "r")

File Modes:

ModeMeaning
rRead
wWrite
aAppend
r+Read + Write

🔹 Reading File

f.read()

🔹 Writing File

f.write("Hello Python")

🔹 Closing File

f.close()

9️⃣ String Processing

Common String Functions:

s.upper() s.lower() s.replace() s.split() s.strip()

🔟 Regular Expressions (RegEx)

Definition:

Regular expressions are used for pattern matching.


Common Symbols

SymbolMeaning
.Any character
^Start of string
$End of string
*Zero or more
+One or more
[a-z]Range

Example:

import re pattern = re.search("python", "I love python")

📘 PAPER 2: OBJECT ORIENTED PROGRAMMING WITH PYTHON UNIT 3 – Classes, Objects & OOP Concepts (university of allahabad)

 

🔴 UNIT 3 – Classes, Objects & OOP Concepts


1️⃣ Class and Object


✅ Class

A class is a blueprint or template used to create objects.

📌 It defines:

  • Data members (variables)

  • Member functions (methods)

Example:

class Student: def show(self): print("This is a student")

✅ Object

An object is an instance of a class.

s1 = Student() s1.show()

🔹 Key Difference

ClassObject
BlueprintReal-world entity
LogicalPhysical
No memoryUses memory

2️⃣ Abstract Data Type (ADT)

✅ Definition

An ADT defines:

  • What operations are to be performed

  • Not how they are implemented

It focuses on behavior, not implementation.

Example:


3️⃣ Classes and Objects in Python

Example Program:

class Person: def __init__(self, name): self.name = name def display(self): print("Name:", self.name) p = Person("Rahul") p.display()

4️⃣ Constructor (__init__)

Definition:

A constructor is a special method used to initialize objects.

Example:

class Student: def __init__(self, roll): self.roll = roll

5️⃣ Features of OOP in Python


🔹 1. Encapsulation

Binding data and methods together.

class Bank: def __init__(self): self.__balance = 5000

Data hiding
✔ Security


🔹 2. Abstraction

Showing essential features and hiding internal details.

Achieved using:


🔹 3. Inheritance

Child class inherits properties of parent class.

class Parent: def show(self): print("Parent") class Child(Parent): pass

Types of Inheritance:

  1. Single

  2. Multiple

  3. Multilevel

  4. Hierarchical

  5. Hybrid


🔹 4. Polymorphism

Same function behaves differently.

Example:

print(len("Python")) print(len([1,2,3]))

6️⃣ Abstract Class

Definition:

An abstract class contains abstract methods (methods without body).

Using abc module:

from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass

7️⃣ Scope in Python

Types of Scope:

  1. Local

  2. Global

  3. Non-local

  4. Built-in


Example:

x = 10 # global def fun(): x = 5 # local print(x)

8️⃣ Multithreading in Python


✅ Definition

Multithreading means executing multiple threads simultaneously.


Is Multithreading Supported in Python?

✔ Yes
❌ But limited due to GIL (Global Interpreter Lock)


Example:

import threading def display(): print("Hello") t = threading.Thread(target=display) t.start()

Advantages:


Disadvantages:

  • Complex debugging

  • GIL limits performance

📘 PAPER 2: OBJECT ORIENTED PROGRAMMING WITH PYTHON UNIT 2 – Python Data Structures (university of allahabad)

 

🔴 UNIT 2 – Python Data Structures


1️⃣ Introduction to Python Data Structures

✅ What is a Data Structure?

A data structure is a way to store, organize, and manage data efficiently so that operations can be performed easily.

Python provides built-in data structures, such as:


2️⃣ Python Data Types (Revisited)

🔹 Mutable Data Types

Data that can be changed after creation.

  • List

  • Dictionary

  • Set

🔹 Immutable Data Types

Data that cannot be changed.

  • Integer

  • Float

  • String

  • Tuple


3️⃣ Python Lists

✅ Definition

A list is an ordered, mutable collection of elements.

Example:

numbers = [10, 20, 30, 40]

🔹 List Characteristics

✔ Ordered
✔ Mutable
✔ Allows duplicate values
✔ Indexed


🔹 List Operations

Accessing elements

print(numbers[0])

Slicing

numbers[1:3]

Adding elements

numbers.append(50)

Removing elements

numbers.remove(20)

4️⃣ List Slicing

Syntax:

list[start : end : step]

Example:

a = [1,2,3,4,5] print(a[1:4])

Output:

[2, 3, 4]

5️⃣ Indexing

  • Positive indexing → Left to right

  • Negative indexing → Right to left

a = [10, 20, 30] print(a[-1]) # 30

6️⃣ List Concatenation

a = [1,2] b = [3,4] c = a + b

Output:

[1,2,3,4]

7️⃣ Searching in Python

🔹 Linear Search

Searches element one by one.

def linear_search(lst, key): for i in lst: if i == key: return True return False

✔ Simple
❌ Slow for large data


🔹 Binary Search

Works only on sorted lists

def binary_search(arr, key): low = 0 high = len(arr)-1 while low <= high: mid = (low+high)//2 if arr[mid] == key: return True elif arr[mid] < key: low = mid+1 else: high = mid-1 return False

✔ Fast
✔ Efficient


8️⃣ Inductive Function Definition

Meaning:

A function defined using:

  1. Base case

  2. Recursive case

Example:

Factorial

def fact(n): if n == 0: return 1 return n * fact(n-1)

9️⃣ Sorting Techniques

🔹 Selection Sort

Steps:

  1. Find minimum

  2. Swap with first element

  3. Repeat

def selection_sort(arr): for i in range(len(arr)): min = i for j in range(i+1, len(arr)): if arr[j] < arr[min]: min = j arr[i], arr[min] = arr[min], arr[i]

🔹 Insertion Sort

def insertion_sort(arr): for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j+1] = arr[j] j -= 1 arr[j+1] = key

🔟 In-Place Sorting

Definition:

Sorting without using extra memory.

✔ Selection Sort
✔ Insertion Sort


1️⃣1️⃣ Tuples

Definition:

Tuple is an ordered but immutable collection.

t = (10, 20, 30)

✔ Faster than list
✔ Used for fixed data


1️⃣2️⃣ Mutability Concept

Data TypeMutable
ListYes
TupleNo
StringNo
DictionaryYes

1️⃣3️⃣ Programs Using Lists

Find Maximum Element

lst = [4, 8, 2, 9] print(max(lst))

Find Minimum Element

print(min(lst))

Find Mean

mean = sum(lst) / len(lst)

📘 PAPER 2: OBJECT ORIENTED PROGRAMMING WITH PYTHON (MCA547) UNIT -1 Object Oriented Programming & Python Basics (university of allahabad)

 

🔴 UNIT 1 Object Oriented Programming & Python Basics


1️⃣ Introduction to Object-Oriented Programming (OOP)

✅ What is OOP?

Object-Oriented Programming is a programming approach that organizes software using objects and classes instead of functions and logic.

✅ Objective of OOP


2️⃣ Basic Concepts of OOP

🔹 1. Object

An object is a real-world entity that has:

  • Properties (data)

  • Behavior (methods)

📌 Example:

car = Car()

🔹 2. Class

A class is a blueprint for creating objects.

📌 Example:

class Car: def start(self): print("Car started")

🔹 3. Encapsulation

Wrapping data and methods together.

Data hiding
✔ Security

Example:

class Student: def __init__(self): self.__marks = 90

🔹 4. Abstraction

Showing only essential details and hiding internal implementation.

✔ Achieved using abstract classes


🔹 5. Inheritance

One class acquires properties of another.

class Child(Parent): pass

🔹 6. Polymorphism

Same function behaves differently.

Example:

print(len("Hello")) print(len([1,2,3]))

3️⃣ Benefits of OOP

✔ Code reusability
✔ Modularity
✔ Easy debugging
✔ Security
✔ Real-world modeling


4️⃣ Applications of OOP

  • Software development

  • Web applications

  • Game development

  • AI & ML

  • Mobile apps

  • GUI applications


5️⃣ Algorithms and Programming

✅ Algorithm

A finite set of steps to solve a problem.

Characteristics:

  • Finite

  • Unambiguous

  • Effective

  • Input & Output defined


6️⃣ Introduction to Python

✅ Features of Python


7️⃣ Structure of Python Program

# Comment print("Hello World")

Components:

  1. Comments

  2. Statements

  3. Indentation

  4. Functions


8️⃣ Variables in Python

Definition:

A variable is a container to store data.

x = 10 name = "Python"

9️⃣ Data Types in Python

Built-in Data Types

TypeExample
int10
float10.5
str"Hello"
boolTrue
list[1,2,3]
tuple(1,2)
set{1,2}
dict{"a":1}

🔟 Operators in Python

Types of Operators:

  1. Arithmetic (+, -, *, /)

  2. Relational (>, <, ==)

  3. Logical (and, or, not)

  4. Assignment (=, +=)

  5. Bitwise (&, |)


1️⃣1️⃣ Control Flow in Python

🔹 Conditional Statements

if a > b: print("A is greater") else: print("B is greater")

🔹 Looping Statements

For Loop

for i in range(5): print(i)

While Loop

i = 0 while i < 5: print(i) i += 1

UGC NET AND CYBERSECURITY BOTH STUDY PLAN

  🎯 Overall Strategy You’ll study: 4–5 hours daily 2 sessions per day Skill + theory balance 🗓 DAILY STUDY STRUCTURE (Repeat...