Q1: Explain Anonymous Function (Lambda) with Examples
✔ Definition
A Lambda function (anonymous function) is a small, unnamed function defined using the lambda
keyword. It is used when a function is required for a short period and contains only a single
expression.
✔ Syntax
Python
lambda arguments : expression
✔ Characteristics
No function name
No def keyword
Contains only one expression
Automatically returns value
Used in functions like map(), filter(), sorted()
✔ Examples
Example 1: Basic
Python
f = lambda x: x * 2
print(f(5)) # Output: 10
Example 2: Multiple arguments
Python
add = lambda a, b: a + b
print(add(3,4)) # 7
Example 3: With map()
Python
l = [1,2,3]
result = list(map(lambda x: x*2, l))
print(result) # [2,4,6]
✔ Conclusion
Lambda functions are useful for short, simple operations and reduce code length.
🔹 Q2: Explain List, Tuple, Dictionary with Example
✔ List
A list is an ordered and mutable collection of elements.
Features:
Allows duplicate values
Can store different data types
Elements can be modified
Example:
Python
l = [1, 2, 3]
l[0] = 10
print(l) # [10,2,3]
✔ Tuple
A tuple is an ordered but immutable collection.
Features:
Cannot be modified
Faster than list
Used for fixed data
Example:
Python
t = (1,2,3)
# t[0] = 10 → error
✔ Dictionary
A dictionary stores data in key-value pairs.
Features:
Keys must be unique
Values can be changed
Unordered (in concept)
Example:
Python
d = {"name":"Ram", "age":20}
d["age"] = 21
print(d)
✔ Difference Summary
Feature
List
Tuple
Dictionary
Mutable
Yes
No
Yes
Format
[]
()
{}
Access
Index
Index
Key
🔹 Q3: Explain Class and Object with Example
✔ Definition
Class → blueprint for creating objects
Object → instance of a class
✔ Components
Attributes (variables)
Methods (functions)
✔ Example
Python
class Student:
def __init__(self, name, marks):
[Link] = name
[Link] = marks
def display(self):
print([Link], [Link])
s1 = Student("Ram", 85)
[Link]()
✔ Explanation
class Student: → defines class
__init__() → constructor (runs automatically)
self → refers to current object
s1 → object of class
✔ Types of Variables
Class variable → shared
Instance variable → unique
✔ Conclusion
Classes help implement object-oriented programming and improve code reusability.
🔹 Q4: Explain Data Structures
✔ Definition
Data structures are used to organize and store data efficiently so that operations can be performed
easily.
✔ Types in Python
List
Tuple
Dictionary
Set
✔ Examples
Python
l = [1,2,3] # list
t = (1,2,3) # tuple
d = {"a":1} # dictionary
s = {1,2,3} # set
✔ Importance
Efficient data management
Faster searching and sorting
Used in algorithms and programming
✔ Applications
Database systems
Machine learning
Data analysis
🔹 Q5: Explain Pandas DataFrame Code Line-by-Line
✔ Code
Python
import pandas as pd
data = {'Name': ['Ram', 'Shyam', 'Mohan'],
'Marks': [85, 90, 78]}
df = [Link](data)
print(df)
print([Link](2))
print(df['Marks'])
✔ Explanation
import pandas as pd
👉 Imports Pandas library and assigns alias pd.
data = {...}
👉 Creates a dictionary where:
Keys → column names
Values → list of data
df = [Link](data)
👉 Converts dictionary into a DataFrame (table)
print(df)
👉 Displays complete table
[Link](2)
👉 Displays first 2 rows
df['Marks']
👉 Selects only Marks column
✔ Output Table
Name
Marks
Ram
85
Shyam
90
Mohan
78
✔ Conclusion
DataFrame is used for tabular data representation and analysis.
🔹 Q6: Explain Supervised Learning with Regression & Simple Linear Regression
✔ Supervised Learning
It is a type of machine learning where:
Model is trained using labeled data
Input and output are known
✔ Examples
Predict marks
Predict house price
✔ Regression Analysis
Regression is used to predict continuous values.
✔ Simple Linear Regression
👉 It shows relationship between:
One input (X)
One output (Y)
✔ Explanation
y → dependent variable
x → independent variable
m → slope
c → intercept
✔ Example
👉 Predict marks based on study hours
✔ Conclusion
Used widely in prediction problems in data science.
🔹 Q7: Explain NumPy with Example
✔ Definition
NumPy is a Python library used for numerical computations and array operations.
✔ Features
Fast processing
Multi-dimensional arrays
Mathematical operations
✔ Example
Python
import numpy as np
a = [Link]([1,2,3])
b = [Link]((2,2))
c = [Link](1,5)
print(a)
print(b)
print(c)
✔ Explanation
[Link]() → creates array
[Link]() → creates zero matrix
[Link]() → creates range array
✔ Applications
Data science
Machine learning
Scientific computing