0% found this document useful (0 votes)
15 views351 pages

Anand First Page

The document is a technical project report submitted by Yallapu Anand for the completion of a Bachelor of Technology in Electronics and Communication Engineering at Jawaharlal Nehru Technological University. It details an internship at Skilldzire focused on a Python course, covering topics such as artificial intelligence, data science, and machine learning. The report includes acknowledgments, a declaration of originality, and a structured outline of the content covered during the internship.

Uploaded by

anand310503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views351 pages

Anand First Page

The document is a technical project report submitted by Yallapu Anand for the completion of a Bachelor of Technology in Electronics and Communication Engineering at Jawaharlal Nehru Technological University. It details an internship at Skilldzire focused on a Python course, covering topics such as artificial intelligence, data science, and machine learning. The report includes acknowledgments, a declaration of originality, and a structured outline of the content covered during the internship.

Uploaded by

anand310503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 351

PYTHON COURSE

A technical project report submitted to Jawaharlal Nehru Technological

University Gurajada Vizianagaram for the partial fulfilment of the

Requirements for the award of the

Degree of

Bachelors of Technology
In

Electronics and Communication Engineering


Submitted by
YALLAPU ANAND
21NT1A0458
Under the Guidance of

Mrs. K. KANTHI KINNERA M. tech, (Ph. D)


Assistant Professor

VISAKHA INSTITUTE OF ENGINEERING AND TECHNOLOGY


(Approved by AICTE, New Delhi & Affiliated to JNTUGV, Vizianagaram)

NAAC ‘A’ ACCEREDITED INSTITUTE

88th Division, Narava, GVMC, Visakhapatnam – 530027, AP


2025

i
INDUSTRIAL INTERNSHIP 4 MONTHS REPORT
2025

INTERNSHIP DURING 2025


(16-12-2024 TO 12-04-2025)

ii
CERTIFICATE

This is to certify that the INTERNSHIP report entitled PYTHON COURSE is


being submitted by YALLAPU ANAND – 21NT1A0458 In partial fulfillment for
the award of the Degree of Bachelor of Technology in Electronics &
Communication Engineering to the Jawaharlal Nehru Technological University,
Gurajada Vizianagaram is a record of bonafied work carried out under my
guidance and supervision. The results embodied in this INTERNSHIP report
have not been submitted to any other University or Institute for the award of
any Degree or Diploma.

Signature of the Guide Signature of the HOD

Dr. B. Jeevana Rao

Assistant Professor Associate Professor

Department of ECE Department of ECE

EXTERNAL EXAMINER

iii
ACCEPTANCE LETTER FROM SKILLDZIRE
ORGANIZATION

iv
CERTIFICATE FROM INTERN ORGANIZATION

v
DECLARATION

I hereby declare that the work presented in this report titled


"PYTHON COURSE Internship Report" is the result of my own
research and study during the internship period at
SKILLDZIRE, undertaken from 16-DEC-2024 to 12-APR-2025.
This report is being submitted in partial fulfilment of the
requirements for the completion of my B.TECH, VISAKHA
INSTITUTE OF ENGINEERING AND
TECHNOLOGY
AFFLIATED TO JNTUGV. All the information, data and results
included in this report are genuine and have been collected,
analyzed, and interpreted by me. Any references or
contributions made by other authors or researchers have
been duly acknowledged in the form of citations and
references. I also confirm that this report has not been
submitted elsewhere for the award of any degree, diploma, or
certificate.

Place: Visakhapatnam Y. ANAND

Date: (21NT1A0458)

vi
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have
supported and guided me throughout my Python Course internship. My
heartfelt thanks to Skill Dzire Organization for providing me with the
opportunity to work and enhance my skills in the field of Python course. I am
deeply thankful to Visakha Institute of Engineering & Technology (VIET)
for offering a supportive environment that made this experience possible. I
extend my sincere appreciation to Dr. G. Satyanarayana, Chairman of VIET,
for his visionary leadership, and Dr. G.V. Pradeep Varma, Principal of VIET,
for his continuous encouragement. I would also like to thank Dr. D. Santha
Rao, Dean of Academics, for his insightful guidance, and Dr. P. Varma,
Training and Placement Officer (TPO), for his efforts in facilitating this
internship. My thanks are also due to Dr. B. Jeevana Rao, Head of the
Department of Electronics and Communication Engineering (ECE), for his
academic support. I am especially grateful to my Project Guide, Mrs. K.
KANTHI KINNERA M. tech, (Ph . D), for her valuable mentorship, constant
encouragement, and expert guidance throughout the internship. Additionally,
I would like to acknowledge the faculty members of the ECE department
whose teachings and support have played a crucial role in my academic
development.

vii
ABSTRACT
Data science encompasses a set of principles, problem definitions, algorithms,
and processes for extracting nonobvious and useful patterns from large data
sets. Many of the elements of data science have been developed in related
fields such as machine learning and data mining. In fact, the terms data
science, machine learning, and data mining are often used interchangeably.
The commonality across these disciplines is a focus on improving decision
making through the analysis of data. However, although data science borrows
from these other fields, it is broader in scope. Machine learning (ML) focuses
on the design and evaluation of algorithms for extracting patterns from data.
Data mining generally deals with the analysis of structured data and often
implies an emphasis on commercial applications. Data science takes all of
these considerations into account but also takes up other challenges, such as
the capturing, cleaning, and transforming of unstructured social media and
web data; the use of big-data technologies to store and process big,
unstructured data sets; and questions related to data ethics and regulation.

viii
CONTENTS
S.NO Name of the Topic/Chapter Page No. From
To

1 Introduction to Artificial Intelligence 1-4


What is AI 1
How AI Works 1
Types of AI 2
Training models of AI 3
Benefits of AI 4
Applications of AI 4
2 Introduction to Data Science 5-8
What is Data Science 5
Where Data Science Needed 5
What is Data, Types of Data 6
How Does a Data Scientist Work 8
Applications Of Data science 8
3 Machine Learning Concepts and Applications 9-10
Why do we need Machine Learning 9
What Makes a Machine learn 9
Benefits of Machine Learning 10
Challenges of Machine Learning 10
4 Introduction to Python for AI & Data Science 11-12
Why python for data science 11
Python Important Features & Interfaces 11
Advantages and disadvantages of python 12
Difference between Python and R Language 12
5 Python Basics and Syntax, Operators & Control 13-23
Statements
Syntax of Python 14
Data Types & Special Characters 15

ix
Operators 17
Strings in Python 19
6 Functions and Scope in Python 24-26
Functions of Python 24
Scopes of python 25
7 Packages & Modules in Python 27-29
8 Exception Handling in Python 30-32
9 Python Data Structures Overview 33-35
10 Lists, Strings, Sets, Tuples, and Dictionaries in 36-39
Python
11 Files and File Handling in Python 40-41
12 Regular Expressions in Python 42-43
13 CONCLUSION 44

x
CHAPTER 1
INTRODUCTION TO AI

Fig1.0

1.1 What is ARTIFICIAL INTELLIGENCE:


Artificial intelligence (AI) is a set of technologies that enable computers to
perform a variety of advanced functions, including the ability to see,
understand and translate spoken and written language, analyse data,
make recommendations, and more.

AI is the backbone of innovation in modern computing, unlocking value


for individuals and businesses. For example, optical character
recognition (OCR) uses AI to extract text and data from images and
documents, turns unstructured content into business-ready structured
data, and unlocks valuable insights. Artificial intelligence is a field of
science concerned with building computers and machines that can
reason, learn, and act in such a way that would normally require human
intelligence or that involves data whose scale exceeds what humans can
analyse.

1.2 HOW AI WORKS:

Fig1.1

1
1.3 Types of Artificial Intelligence:
Artificial intelligence can be organized in several ways, depending on
stages of development or actions being performed.

For instance, four stages of AI development are commonly recognized.

Reactive machines: Limited AI that only reacts to different kinds of


stimuli based on preprogrammed rules. Does not use memory and thus
cannot learn with new data. IBM’s Deep Blue that beat chess champion
Garry Kasparov in 1997 was an example of a reactive machine.

Limited memory: Most modern AI is considered to be limited memory.


It can use memory to improve over time by being trained with new data,
typically through an artificial neural network or other training model.
Deep learning, a subset of machine learning, is considered limited
memory artificial intelligence time

Theory of mind: Theory of mind AI does not currently exist, but


research is ongoing into its possibilities. It describes AI that can
emulate the human mind and has decision-making capabilities equal
to that of a human, including recognizing and remembering emotions
and reacting in social situations as a human would.

Self-aware: A step above theory of mind AI, self-aware AI describes a


mythical machine that is aware of its own existence and has the
intellectual and emotional capabilities of a human. Like theory of mind
AI, self-aware AI does not currently exist.

Fig 1.2

2
1.4 Artificial Intelligence Training Models:
Supervised learning is a machine learning model that maps a specific
input to an output using labelled training data (structured data).

Unsupervised learning is a machine learning model that learns


patterns based on unlabelled data (unstructured data). Unlike
supervised learning, the end result is not known ahead of time. Rather,
the algorithm learns from the data, categorizing it into groups based on
attributes. For instance, unsupervised learning is good at pattern
matching and descriptive modelling.

In addition to supervised and unsupervised learning, a mixed approach


called semi-supervised learning is often employed, where only some of
the data is labelled. In semi-supervised learning, an end result is
known, but the algorithm must figure out how to organize and structure
the data to achieve the desired results.

Fig 1.3

3
1.5 Benefits of AI:

Fig 1.4
1.6 Applications of AI:

Fig 1.5

4
CHAPTER : 2
What is Data Science
Data Science is a combination of multiple disciplines that uses statistics,
data analysis, and machine learning to analyse data and to extract
knowledge and insights from it.

Data Science is about data gathering, analysis and decision-


making.

Data Science is about finding patterns in data, through analysis, and make
future predictions.

 By using Data Science, companies are able to make:


 Better decisions (should we choose A or B)
 Predictive analysis (what will happen next?)
 Pattern discoveries (find pattern, or maybe hidden information in the
data)

2.1 Where is Data Science Needed:


 For route planning: To discover the best routes to ship
 To foresee delays for flight/ship/train etc. (through predictive
analysis)
 To create promotional offers
 To find the best suited time to deliver goods
 To forecast the next years revenue for a company
 To analyse health benefit of training
 To predict who will win elections

Data Science can be applied in nearly every part of a business where data is
available. Examples are:

 Consumer goods
 Stock markets
 Industry
 Politics
 Logistic companies
 E-commerce

2.2 What is Data:


Data is a collection of information.

5
One purpose of Data Science is to structure data, making it
interpretable and easy to work with.

Data can be categorized into two groups:

 Structured data
 Unstructured data

Fig 2.1
2.3 How Does a Data Scientist Work:
A Data Scientist requires expertise in several backgrounds:

 Machine Learning
 Statistics
 Programming (Python or R)
 Mathematics
 Databases

6
Fig 2.2
1. Problem Statement:

No work starts without motivation, Data science is no exception though.


It’s really important to declare or formulate your problem statement
very clearly and precisely. Your whole model and it’s working depend
on your statement. Many scientists consider this as the main and much
important step of Date Science. So, make sure what’s your problem
statement and how well can it add value to business or any other
organization.

2. Data Collection:

After defining the problem statement, the next obvious step is to go in


search of data that you might require for your model. You must do good
research, find all that you need. Data can be in any form i.e.
unstructured or structured. It might be in various forms like videos,
spreadsheets, coded forms, etc. You must collect all these kinds of
sources.

3. Data Cleaning:

As you have formulated your motive and also you did collect your data,
the next step to do is cleaning. Yes, it is! Data cleaning is the most
favourite thing for data scientists to do. Data cleaning is all about the
removal of missing, redundant, unnecessary and duplicate data from
your collection. There are various tools to do so with the help of
programming in either R or Python. It’s totally on you to choose one of
them. Various scientist has their opinion on which to choose. When it
comes to the statistical part, R is preferred over Python, as it has the
privilege of more than 12,000 packages. While python is used as it is
fast, easily accessible and we can perform the same things as we can in
R with the help of various packages.

4. Data Analysis and Exploration:

7
It’s one of the prime things in data science to do and time to get inner
Holmes out. It’s about analysing the structure of data, finding hidden
patterns in them, studying behaviours, visualizing the effects of one
variable over others and then concluding. We can explore the data with
the help of various graphs formed with the help of libraries using any
programming language. In R, GGplot is one of the most famous models
while Matplotlib in Python.

5. Data Modelling:

Once you are done with your study that you have formed from data
visualization, you must start building a hypothesis model such that it
may yield you a good prediction in future. Here, you must choose a good
algorithm that best fit to your model. There different kinds of algorithms
from regression to classification, SVM (Support vector machines),
Clustering, etc. Your model can be of a Machine Learning algorithm.
You train your model with the train data and then test it with test data.
There are various methods to do so. One of them is the K-fold method
where you split your whole data into two parts, one is Train and the
other is test data. On these bases, you train your model.

6. Optimization and Deployment:

You followed each and every step and hence build a model that you feel
is the best fit. But how can you decide how well your model is
performing? This where optimization comes. You test your data and find
how well it is performing by checking its accuracy. In short, you check
the efficiency of the data model and thus try to optimize it for better
accurate prediction. Deployment deals with the launch of your model
and let the people outside there to benefit from that. You can also obtain
feedback from organizations and people to know their need and then to
work more on your model.

2.4 Applications of Data Science:

Fig 2.3

8
CHAPTER : 3
Machine Learning concepts and Applications
Machine learning (ML) allows computers to learn and make decisions without
being explicitly programmed. It involves feeding data into algorithms to
identify patterns and make predictions on new data. Machine learning is used
in various applications, including image and speech recognition, natural
language processing, and recommender systems.

3.1 Why do we need Machine Learning?


Machine Learning algorithm learns from data, trains on patterns, and
solves or predicts complex problems beyond the scope of traditional
programming. It drives better decision-making and tackles intricate
challenges efficiently.

 Solving Complex Business Problems


 Handling Large Volumes of Data
 Automate Repetitive Tasks
 Personalized User Experience
 Self-Improvement in Performance

3.2 What Makes a Machine “Learn”?


A machine “learns” by recognizing patterns and improving its
performance on a task based on data, without being explicitly
programmed.

The process involves:

Data Input: Machines require data (e.g., text, images, numbers) to


analyse.
Algorithms: Algorithms process the data, finding patterns or
relationships.

Model Training: Machines learn by adjusting their parameters based


on the input data using mathematical models.

Feedback Loop: The machine compares predictions to actual outcomes


and corrects errors (via optimization methods like gradient descent).

Experience and Iteration: Repeating this process with more data


improves the machine’s accuracy over time.

Evaluation and Generalization: The model is tested on unseen data


to ensure it performs well on real-world tasks.

9
3.3 Importance of Data in Machine Learning:
Data is the foundation of machine learning (ML). Without quality data,
ML models cannot learn, perform, or make accurate predictions.

 Data provides the examples from which models learn patterns


and relationships.
 High-quality and diverse data improves model accuracy and
generalization.
 Data ensures models understand real-world scenarios and adapt
to practical applications.
 Features derived from data are critical for training models.
 Separate datasets for validation and testing assess how well the
model performs on unseen data.
 Data fuels iterative improvements in ML models through
feedback loops.

Fig 3.0

3.5 Challenges of Machine Learning:

Fig 3.1

10
CHAPTER : 4
PYTHON
Python is a programming language widely used by Data Scientists.

Python has in-built mathematical libraries and functions, making it easier to


calculate mathematical problems and to perform data analysis.

4.1 Why Python for Data Science?


Python is favoured in data science due to its readability, simplicity, and
versatility. Its extensive libraries and frameworks streamline complex
tasks, allowing data scientists to focus on problem-solving rather than
coding intricacies.

Fig 4.1

4.2 Features of Python:

Fig 4.2

11
4.3 Key Libraries and Tools:
NumPy: A fundamental library for numerical operations in Python,
supporting large, multi-dimensional arrays and matrices.

pandas: A powerful library for data manipulation and analysis, offering


data structures like Data Frames to handle structured data efficiently.

Scikit-learn: A comprehensive library for machine learning, providing


simple and efficient data mining and analysis tools.

Matplotlib and Seaborn: Libraries for creating static, animated, and


interactive visualizations, helping to understand data patterns and
trends

Fig 4.3

4.4 Advantages and Disadvantages of Python:

Fig 4.4

12
4.5 Applications of Python:

Fig 4.5

Benefits of Python:

Fig 4.6

4.6 Difference between Python and R Language

Fig 4.7

13
CHAPTER: 5
Python Syntax, Data Types & Operators
Python is known for its clean and readable syntax, which makes it an
excellent language for beginners and professionals working in AI, data
science, and software development.

5.1 Python Syntax


Python syntax refers to the set of rules that define how a Python program is
written and interpreted. One of the most distinctive and beginner-friendly
aspects of Python is its clean and readable syntax. Unlike many other
programming languages that use curly braces {} to define code blocks, Python
uses indentation (whitespace). This means that consistent indentation is not
just a style, but a requirement in Python—usually 4 spaces are used per
indentation level.

A Python program is made up of statements and expressions. Statements are


instructions (like if, for, or def) that perform actions, while expressions are
combinations of values and operators that evaluate to a result. Python is case-
sensitive, so Name, name, and NAME are all treated as different identifiers.

Some key points of Python syntax:

Comments start with # and are ignored by the interpreter. Use them to explain
your code.
Variables do not require a type declaration; the type is inferred from the value
(e.g., x = 10).

Functions are defined using the def keyword, and blocks of code are
structured using colons (:) followed by indented lines.

Control structures like if, elif, else, for, and while are written in a natural,
readable way.

Importing modules is done using the import keyword.

Example:

# This is a comment

def greet(name):

if name:

print (f"Hello, {name}!")

else:

14
print ("Hello, Guest!")

greet("Alice")

Python also supports a REPL (Read-Eval-Print Loop) mode, where you can
type Python code line by line and see immediate results. This makes it great
for quick testing and learning. Overall, Python's syntax emphasizes
readability, simplicity, and consistency, which is why it's so widely loved by
beginners and professionals alike.

Fig 5.1

5.2 Python Data Types:


In Python, data types define the kind of value a variable can hold, and they
are essential for writing correct and efficient programs. Python is a
dynamically typed language, which means you don't need to declare the data
type of a variable explicitly—Python detects it automatically at runtime. The
built-in data types in Python can be broadly categorized into several types:

15
◆ 1. Numeric Types

These include:

int – for integers (e.g., 10, -5)

float – for decimal numbers (e.g., 3.14, -0.01)

complex – for complex numbers (e.g., 2 + 3j)

◆ 2. Sequence Types

These are ordered collections:

str – string, a sequence of characters (e.g., "Hello")

list – mutable sequence of items (e.g., [1, 2, 3])

tuple – immutable sequence (e.g., (4, 5, 6))

◆ 3. Set Types

set – unordered collection of unique items (e.g., {1, 2, 3})

frozen set – like a set but immutable

◆ 4. Mapping Type

dict – a collection of key-value pairs (e.g., {"name": "Alice", "age": 25})

◆ 5. Boolean Type

bool – represents True or False, typically used in conditional expressions

◆ 6. Binary Types

Used to handle binary data:

bytes – immutable sequence of bytes

bytearray – mutable sequence of bytes

memoryview – memory-efficient view of bytes

16
◆ 7. None Type

NoneType – represents the absence of a value, written as None

Example:

a = 10 # int

b = 3.14 # float

c = "Python" # str

d = [1, 2, 3] # list

e = {"key": 1} # dict

f = True # bool

Python also allows you to check the type of a variable using the built-in type()
function, and you can convert between types using type casting, such as int(),
float(), str(), etc. Understanding data types is foundational for writing correct
Python code, as operations and functions behave differently depending on the
type of data they work with.

5.3 Operators:
In Python, operators are special symbols or keywords used to perform
operations on variables and values. Python supports several types of
operators that enable arithmetic operations, comparisons, logical decisions,
bitwise manipulations, and more. These operators make it easier to write
expressions that carry out calculations and control flow in programs.

1. Arithmetic Operators

Used to perform basic mathematical operations:

+ (Addition), - (Subtraction), * (Multiplication), / (Division)

// (Floor Division), % (Modulus), ** (Exponentiation)

Example:

a=5

b=2

print (a + b) # 7

print (a ** b) # 25

2. Comparison (Relational) Operators

17
Used to compare values and return a boolean result:

== (Equal to),!= (Not equal to)

> (Greater than), < (Less than)

>= (Greater than or equal to), <= (Less than or equal to)

Example:

x = 10

y = 20

print (x < y) # True

3. Logical Operators

Used to combine conditional statements:

and – True if both conditions are true

or – True if at least one condition is true

not – Reverses the result (True becomes False)

Example:

a=5

print (a > 2 and a < 10) # True

4. Assignment Operators

Used to assign values to variables:

=, +=, -=, *=, /=, %=, **=, //=

Example:

x=5

x += 3 # x becomes 8

5. Bitwise Operators

Used to perform operations on binary representations:

& (AND), | (OR), ^ (XOR)

~ (NOT), << (Left Shift), >> (Right Shift)

18
Example:

a=5 # 0101

b=3 # 0011

print (a & b) # 1 (0001)

6. Membership Operators

Used to test if a value is a member of a sequence (like list, string, tuple):

in – returns True if value exists

not in – returns True if value does not exist

Example:

fruits = ["apple", "banana"]

print ("apple" in fruits) # True

7. Identity Operators

Used to compare memory locations of objects:

is – returns True if two variables point to the same object

is not – returns True if they do not

Example:

x = [1, 2, 3]

y=x

print (x is y) # True

5.4 Control Statements:


Control statements in Python are used to manage the flow of execution in a
program. They allow you to make decisions, repeat actions, or jump out of
certain code blocks based on conditions. The three main types of control
statements are conditional statements, looping statements, and loop control
statements.

◆ Conditional Statements
These statements let your program make decisions based on certain
conditions. Python uses:

19
if – executes a block if the condition is true

elif – checks another condition if the previous one was false

else – executes a block if all previous conditions were false

Example:

x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

◆ Looping Statements
Loops are used to repeat a block of code multiple times.

for loop – iterates over a sequence (like a list, string, or range)

while loop – repeats as long as a condition is true

Examples:

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

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

◆ Loop Control Statements


These are used to alter the flow inside loops:

break – exits the loop immediately

continue – skips the rest of the current iteration

20
pass – does nothing, used as a placeholder

Example:

for i in range (5):


if i == 3:
break
print(i) # prints 0, 1, 2

for i in range (5):


if i == 3:
continue
print(i) # prints 0, 1, 2, 4
Control statements are the backbone of decision-making and repetition in
Python, making it possible to write intelligent, responsive, and efficient
programs.

5.4 Strings in Python:


Strings in Python

In Python, a string is a sequence of characters used to represent textual data


such as words, sentences, or even numbers written as text. Strings are
enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """) for
multi-line strings. Python strings are immutable, meaning once a string is
created, its characters cannot be changed individually—you can only create a
new string through operations. Strings support a variety of operations like
concatenation, slicing, and iteration, and are widely used in almost every
Python program.

Python offers many powerful string methods to work with text, such as:

upper () – converts to uppercase

lower () – converts to lowercase

title () – capitalizes each word

21
strip () – removes whitespace from both ends

replace (old, new) – replaces parts of the string

split () – splits the string into a list

join () – joins elements of a list into a single string

find () – returns the index of the first match

startswith () / endswith () – checks how a string begins or ends

Example:

text = “Python is awesome! “

print(text.strip().upper()) # Output: PYTHON IS AWESOME!

Strings can also be indexed and sliced:

word = "Python"

print(word[0]) # P (first character)

print(word[-1]) # n (last character)

print (word [1:4]) # yth (slicing from index 1 to 3)

Python also supports string formatting, which allows you to embed variables
into strings:

Using f-strings: f"Hello, {name}!"

Using .format(): "Hello, {}”. format(name)

Using % formatting (older style): "Hello, %s" % name

A string is a sequence of characters which is enclosed in quotes.

22
There are basically 3 types of operators supported by string:

 Basic Operators: There are two types of basic operators in string. They are
“+” and “*”.
1. Concatenation Operator (+): the concatenation operator concatenates
two strings and forms a new string.
2. Replication Operator (*): It is used to repeat a string number of times
the string will be repeated the number of times is given by the integer
value.
 Membership operators: To test whether a value is present in a sequence.
 Relational Operators: All the comparisons operators i.e., (<,>, <=,>=, == ,!=,
<>)
 Slice Notation: String Slice can be defined as substring which is the part of
string. Therefore, further substring can be obtained from a string.

Strings in Python are versatile and essential, used in everything from simple
output messages to file handling, data parsing, and user input. Their
flexibility and the wide range of methods make them one of the most
important data types in Python.

23
CHAPTER:6
Functions and Scope in Python
In Python: functions, modules, and exception handling. These concepts help
developers write organized, reusable, and error-free code, making Python a
powerful and efficient programming language for AI, data science, and
software development.

6.1 Functions in Python:


Functions in Python

In Python, a function is a reusable block of code that performs a specific task.


Functions help organize code, make it more readable, reduce repetition, and
allow for modular programming. You can define a function using the def
keyword, followed by the function name and parentheses (), which may
include parameters—placeholders for the inputs the function can receive. The
code inside the function is indented and runs only when the function is called.
If a function should return a result, you use the return statement. In

• Built-in Functions such as print (), len (), and range ().

• User-defined Functions, where programmers create their own functions


using the def

keyword.

• Function Parameters and Return Values, enabling functions to accept


input and return

output for better flexibility.

• Lambda Functions, which are small anonymous functions used for quick,
short operations.

Example:

def greet(name):

return f"Hello, {name}!"

print(greet("Alice")) # Output: Hello, Alice!

Python also supports default arguments, where parameters can have default
values:

24
python

Copy

Edit

def greet(name="Guest"):

print (f"Welcome, {name}!")

Functions can take any number of arguments using:

*args for variable-length positional arguments

**kwargs for variable-length keyword arguments

Python also allows anonymous functions using the lambda keyword. These
are short, one-line functions used for simple tasks, especially with functions
like map (), filter (), and sorted ().

Example:

square = lambda x: x * x

print (square (5)) # Output: 25

6.2 Scopes of Python


In Python, scope refers to the visibility and accessibility of variables
within different parts of a program. Scope determines where a variable
is accessible and where not. In order to understand how variables
behave within functions and how they interact with each other, it is
crucial to understand scope.

Python has two main types of scope:

Local scope:
 Variables declared within a function have local scope. They are
accessible only within the function in which they are defined.
 Local variables are created when the function is called and
destroyed when it exits.
 Local variables cannot be accessed from outside the function.

25
Global Scope:
 Variables declared outside of any function or at the top level of a
script have global scope. They are accessible throughout the
program.
 During program startup, global variables are created in memory
and remain there until the program ends.
 Global variables can be accessed from any function within the
program.

Nested scope:
 Python allows nested functions, where one function is defined
inside another.
 During nested functions, the inner function has access to
variables in the outer (enclosed) function.
 The inner function's scope is called "nested scope" because it
includes both its local scope and the enclosing function's scope.

26
CHAPTER: 7
Packages and Modules in Python
Introduction
Python is a high-level, general-purpose programming language widely used in
various domains including data science, machine learning, web development,
and automation. One of Python’s key strengths is its modular structure,
which allows developers to organize code into reusable components. This
modularity is achieved through the use of modules and packages, which play
a vital role in organizing, maintaining, and scaling Python projects effectively.

Modules in Python
A module is a file containing Python code that is written for reuse. It typically
consists of functions, classes, and variables that serve specific functionalities.
The primary goal of a module is to break down large programs into smaller,
manageable, and logically organized parts. This enhances code readability,
promotes reuse, and simplifies debugging and maintenance.

Modules form the foundational building blocks of Python programs. They can
be standard (built-in to Python), third-party (installed externally), or user-
defined (created by the developer). Using modules also allows for separation
of concerns, where each module is responsible for a specific part of the
program logic, reducing complexity in large codebases.

27
Packages in Python
A package is a hierarchical file structure that contains multiple modules
grouped together to form a collection of related functionalities. Packages allow
developers to organize their modules into directories, thereby creating a
scalable project structure. The presence of a special initialization file in the
directory indicates to Python that it should treat the directory as a package.

Packages are essential when working on large projects that involve multiple
components. By categorizing similar modules into packages, developers can
avoid naming conflicts, improve code organization, and enable better
navigation through the codebase. Packages can also contain sub-packages,
allowing for multi-level structuring of code.

Advantages of Using Modules and Packages

The use of modules and packages provides several benefits in software


development:

 Reusability: Code can be written once and reused in different


programs.

 Maintainability: Issues can be isolated and fixed within individual


modules or packages.

 Readability: Well-structured code is easier to understand and modify.

 Namespace Management: Helps avoid conflicts by isolating function


and variable names.

 Scalability: Supports growth of codebase in an organized manner,


especially in large projects.

In professional environments, especially in domains like data science,


modular programming with well-organized packages and modules is
considered a best practice.

Relevance in Data Science


In the field of data science, modular code organization is crucial due to the
multifaceted nature of tasks such as data preprocessing, analysis,
visualization, and model evaluation. Data scientists frequently work with
various Python packages designed for specific tasks. Understanding the
structure and use of modules and packages enables data scientists to build
efficient, reusable, and well-organized code pipelines.

During the course of my internship in the domain of data science, I learned


the importance of modular programming when dealing with data workflows.
The use of packages and modules made it easier to manage code, automate

28
repetitive processes, and collaborate effectively in a team environment. This
approach not only improved the quality of the code but also enhanced overall
productivity.
Modules in Python are essential components that allow programmers to
organize code into separate files and reuse functionality across different
programs. A module is simply a file containing Python code—such as
functions, classes, or variables—that can be imported and used in another
Python script. Python supports various types of modules, including built-in
modules like math, os, and datetime, which come pre-installed and provide
powerful features for mathematical operations, file handling, and date/time
manipulation. Users can also create their own custom modules, known as
user-defined modules, to structure their code better and enhance reusability.
Additionally, third-party modules like numpy, pandas, matplotlib, and flask
can be installed using Python’s package manager pip to perform specific tasks
such as data analysis, visualization, and web development. Modules can be
imported using the import statement, and specific functions or classes can be
brought in using from module import name. By using modules, Python
promotes modular programming, which leads to cleaner, more manageable
code, encourages reusability, reduces redundancy, and improves overall
program structure. Whether for small scripts or large applications, modules
play a vital role in efficient and effective Python development.

29
CHAPTER: 8
EXCEPTION HANDLING IN PYTHON
Introduction
In any programming language, errors are a natural part of the development
process. Python provides a structured way to detect and handle these errors
using a mechanism called exception handling. This allows programs to
respond to unexpected situations without crashing, thereby improving
robustness, user experience, and overall software reliability.

Exception handling is a critical concept in Python, particularly in data-driven


applications where unpredictable user input, file errors, or network issues
can arise. Effective handling of exceptions ensures smooth execution and
helps in debugging, logging, and maintaining code efficiently.

Understanding Exceptions
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions are not necessarily errors
in logic; they often result from conditions that are beyond the control of the
program, such as attempting to access a file that does not exist or dividing a
number by zero.

In Python, exceptions are objects that represent these error conditions. When
an exception occurs, Python immediately stops the current flow of the
program and looks for a way to handle the exception. If not handled, the
program terminates and displays an error message, commonly referred to as
a traceback.

Exception Handling Mechanism


Python uses a structured approach to manage exceptions through specific
keywords that help detect and respond to exceptions. The handling
mechanism allows developers to define blocks of code to try and detect errors,
and to define alternative behaviours in case an error occurs. This approach
separates normal program logic from error handling, which leads to clearer
and more maintainable code.

The exception handling structure in Python includes the following:

 A block to attempt execution.

 One or more blocks to handle specific or general exceptions.

 An optional block that executes regardless of whether an exception


occurred.

30
 An optional block for cleanup actions.

This mechanism provides flexibility and control over how different types of
exceptions are managed and ensures that the program can continue running
or exit gracefully.

Benefits of Exception Handling


Proper use of exception handling brings multiple benefits to Python programs,
especially in complex or user-facing applications. Some key advantages
include:

 Error Isolation: Helps identify exactly where the error occurred without
affecting the rest of the code.

 Improved User Experience: Allows for graceful failure and user-friendly


error messages instead of program crashes.

 Code Clarity: Separates normal program logic from error handling,


making code cleaner and easier to understand.

 System Stability: Prevents unexpected terminations by managing rare


or unanticipated situations safely.

 Maintenance & Debugging: Makes the program easier to maintain and


debug by providing detailed error messages and control flow.

Exception Hierarchy and Custom Exceptions


Python’s built-in exception classes are arranged in a hierarchy, starting from
a base class. This structure allows developers to catch a broad category of
errors or target specific ones. Additionally, Python allows developers to define
their own custom exceptions by creating new classes. This is especially useful
in larger projects, including data science applications, where domain-specific
errors need to be clearly identified and handled.

Custom exception handling improves code readability and gives a clearer


understanding of how certain errors are treated uniquely, contributing to
better error tracking and documentation.

Relevance in Data Science


In the domain of data science, exception handling is crucial due to the
unpredictability of data sources and system resources. Whether it is reading
from external files, processing real-time data, or interacting with APIs,
exceptions can occur at multiple stages. Proper handling ensures that data
pipelines do not break due to a single failure and that logs are maintained for
future analysis.

31
During my internship in the field of data science, I encountered several
scenarios where exception handling became necessary—for instance, when
handling missing values, managing file loading issues, or connecting to
external databases. Implementing structured exception handling helped me
build resilient scripts that could run reliably in different environments with
varying data inputs.

Conclusion
Exception handling is a fundamental aspect of writing robust and
professional-grade Python applications. It allows developers to anticipate and
manage errors effectively, ensuring that programs behave predictably even
under unexpected conditions. In data science and other real-world
applications, the ability to handle exceptions gracefully not only improves
performance but also enhances the reliability and trustworthiness of the
system. My internship experience underscored the importance of mastering
exception handling to create stable, scalable, and user-friendly Python
solutions.

32
CHAPTER: 9
PYTHON DATA STRCTURES
Introduction
Data structures are the foundational building blocks of any programming
language. In Python, data structures are used to store, organize, and manage
data efficiently. They provide a means of performing operations on data and
are essential for solving complex computational problems. Python offers a rich
collection of built-in data structures that are both flexible and easy to use,
which makes the language especially powerful for data science and software
development.

Understanding and utilizing Python’s data structures effectively is crucial for


writing optimized and maintainable code. They support efficient data
manipulation, enable clear program logic, and allow for better performance
across a wide range of applications.

Types of Data Structures in Python


Python provides several built-in data structures, each with unique properties,
performance characteristics, and use cases. These can be categorized into two
main types: primitive and non-primitive data structures.

1. Primitive Data Structures

These are the most basic data types in Python, including:

 Integers

 Floats

 Strings

 Booleans
While not considered data structures in the traditional sense, these primitives
form the basis for more complex types.

2. Non-Primitive Data Structures

These include more advanced structures that are capable of storing multiple
elements and performing operations on them. The primary non-primitive data
structures in Python are:

 Lists: Ordered and mutable collections of elements.

 Tuples: Ordered but immutable sequences.

 Sets: Unordered collections of unique elements.

33
 Dictionaries: Key-value pairs for efficient lookup and storage.

Each of these structures is implemented in a way that allows for dynamic


memory management, and they can grow or shrink as needed, which makes
them more flexible than traditional arrays in other languages.

Importance in Programming and Data Science


Efficient use of data structures is essential for solving real-world problems.
They help in organizing data logically and performing operations such as
insertion, deletion, traversal, and searching in a time-efficient manner.
In the context of data science, choosing the right data structure can greatly
impact the performance and scalability of data pipelines and analytical
models. For example, dictionaries are often used for mapping categorical
variables, while lists and tuples are commonly used for storing data records
or feature sets.

Python’s built-in data structures are often used in combination with third-
party libraries like pandas, which extends their functionality for handling
structured data such as tables and time series.

Key Features of Python Data Structures


 Dynamic Typing: Python data structures can hold mixed data types,
adding flexibility during implementation.

 Memory Efficiency: Python manages memory dynamically, which


simplifies development while still allowing efficient performance.

 Ease of Use: The syntax and operations associated with Python’s data
structures are intuitive and user-friendly.

 Rich Functionality: Python provides a wide range of built-in methods


for manipulating data structures, enhancing productivity and code
readability.

 Extensibility: Built-in structures can be extended or customized to


create more complex structures such as stacks, queues, and graphs
using object-oriented programming.

Applications in Real-World Projects


During the course of my internship in data science, I worked with large and
complex datasets requiring structured organization and efficient data
manipulation. Python data structures played a key role in managing this data
effectively.

34
Tasks such as data cleaning, transformation, and aggregation were greatly
facilitated by using dictionaries, lists, and sets. Understanding the underlying
structure of data allowed me to implement faster and more reliable solutions,
especially when dealing with large-scale operations or real-time data.

Data structures also supported integration with various tools and libraries,
enabling seamless development of end-to-end data workflows.

35
Chapter:10
Lists, Tuples, Sets, Dictionaries and Strings in
Python
List
A list in Python is a dynamic, ordered collection that can store elements of
different data types such as integers, floats, strings, or even other lists (nested
lists). Lists are mutable, so you can change, add, or delete elements without
creating a new list. They are defined using square brackets []. Lists are
versatile and widely used for storing a sequence of items such as a list of
student names, shopping items, or daily temperatures.

Common methods include:

 append () – adds an item to the end

 insert () – inserts an item at a specific index

 pop () – removes and returns the last element

 sort () – sorts the list in ascending order

 reverse () – reverses the list

Example:

fruits = ["apple", "banana", "cherry"]


fruits. Append("orange")

print(fruits)

Output = ['apple', 'banana', 'cherry', 'orange']

String
A string is a sequence of Unicode characters used to represent text. Strings
are immutable, meaning once created, their content cannot be changed. You
can perform various operations on strings like slicing, searching, formatting,
and joining. Strings are defined using single ' or double " quotes, and multiline
strings use triple quotes ''' or """.

Common methods include:

 upper () – converts to uppercase

 lower () – converts to lowercase

 find () – finds a substring

36
 replace () – replaces part of the string

 split () – splits the string into a list

Example:

python

message = "Python is fun"

print (message. Upper ())

Output = PYTHON IS FUN

Tuple
A tuple is a collection similar to a list but immutable, meaning once it's
created, you cannot add, remove, or change elements. Tuples are defined
using parentheses (). Because they are immutable, they can be used as
dictionary keys or elements in a set, which lists cannot do. Tuples are
usually used when the data should not be changed throughout the program,
like coordinates (x, y) or months of the year.

Common operations:

 Accessing elements via index

 Iterating with loops

 Using count () and index () methods

Example:

python

dimensions = (10, 20, 30)

print (dimensions [1])

Output = 20

Advantages:

 Faster than lists (since immutable)

 Safer for storing fixed data

Dictionary
A dictionary is an unordered, mutable collection of key-value pairs. Each
key must be unique and immutable (like strings, numbers, or tuples).
Dictionaries are written using curly braces {}. They are commonly used to
store data like student records, configurations, or any structured data.

37
Common methods:

 get () – safely gets a value by key

 keys () – returns all keys

 values () – returns all values

 items () – returns all key-value pairs

 update () – updates the dictionary with another dictionary

Example:

python

student = {"name": "Alice", "age": 20, "grade": "A"}

print(student["name"])

Output = Alice

Use Cases:

 Storing structured data (e.g., JSON-like)

 Fast lookups based on keys

 Grouping related values together

Set
A set is a collection of unordered, unique items. Sets are useful when you
want to ensure there are no duplicate entries. Sets are mutable, meaning you
can add or remove elements, but they do not support indexing or slicing
because they are unordered. Sets are ideal for operations like union,
intersection, and difference between groups.

Common methods:

 add () – adds an element

 remove () – removes an element

 union () – combines two sets

 intersection () – finds common elements

 difference () – elements in one set but not another

Example:

python

set1 = {1, 2, 3}

38
set2 = {3, 4, 5}

print (set1 & set2)

Output = {3}

39
Chapter: 11
Files and File Handling in Python
Files and File Handling in Python
In Python, file handling allows you to create, read, write, and delete files
directly from your Python program. This is especially useful when you want
to store data permanently, process text files, or interact with external files like
logs, reports, or configurations. Python provides built-in functions for file
handling, and the most common one is the open () function. This function is
used to open a file and returns a file object, which lets you perform various
operations on the file.

When opening a file, you must specify the mode:

 "r" – Read (default mode; file must exist)

 "w" – Write (creates a new file or overwrites if it exists)

 "a" – Append (adds data to the end of the file)

 "x" – Create (creates a file, returns error if file exists)

 Add "b" for binary mode (e.g., "rb" for read binary)

 Add "+" to read and write ("r+", "w+", etc.)

To read data from a file, you can use:

 read () – reads the entire file as a string

 readline () – reads one line at a time

 readlines () – reads all lines and returns a list

To write to a file, use write () or writelines (). After you're done working with a
file, it’s important to close it using close () to free up system resources.
However, the better way to handle files in Python is using a with block (also
called a context manager), which automatically closes the file when done.
Example (writing and reading a file):

python

# Writing to a file

with open ("example.txt", "w") as file:

file.write ("Hello, this is a test file.\n")

file.write("Python is fun!")

40
# Reading from a file

with open ("example.txt", "r") as file:

content = file.read()

print(content)

Advantages of Python's file handling include simplicity, cross-platform


compatibility, and powerful tools for both text and binary file operations. It is
widely used in data processing, saving logs, creating reports, and handling
user inputs.

41
INDUSTRIAL INTERNSHIP 4 MONTHS REPORT
2025

INTERNSHIP DURING 2025


(16-12-2024 TO 12-04-2025)

ii
CERTIFICATE

This is to certify that the INTERNSHIP report entitled PYTHON COURSE is


being submitted by YALLAPU ANAND – 21NT1A0458 In partial fulfillment for
the award of the Degree of Bachelor of Technology in Electronics &
Communication Engineering to the Jawaharlal Nehru Technological University,
Gurajada Vizianagaram is a record of bonafied work carried out under my
guidance and supervision. The results embodied in this INTERNSHIP report
have not been submitted to any other University or Institute for the award of
any Degree or Diploma.

Signature of the Guide Signature of the HOD

Dr. B. Jeevana Rao

Assistant Professor Associate Professor

Department of ECE Department of ECE

EXTERNAL EXAMINER

iii
ACCEPTANCE LETTER FROM SKILLDZIRE
ORGANIZATION

iv
CERTIFICATE FROM INTERN ORGANIZATION

v
DECLARATION

I hereby declare that the work presented in this report titled


"PYTHON COURSE Internship Report" is the result of my own
research and study during the internship period at
SKILLDZIRE, undertaken from 16-DEC-2024 to 12-APR-2025.
This report is being submitted in partial fulfilment of the
requirements for the completion of my B.TECH, VISAKHA
INSTITUTE OF ENGINEERING AND
TECHNOLOGY
AFFLIATED TO JNTUGV. All the information, data and results
included in this report are genuine and have been collected,
analyzed, and interpreted by me. Any references or
contributions made by other authors or researchers have
been duly acknowledged in the form of citations and
references. I also confirm that this report has not been
submitted elsewhere for the award of any degree, diploma, or
certificate.

Place: Visakhapatnam Y. ANAND

Date: (21NT1A0458)

vi
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have
supported and guided me throughout my Python Course internship. My
heartfelt thanks to Skill Dzire Organization for providing me with the
opportunity to work and enhance my skills in the field of Python course. I am
deeply thankful to Visakha Institute of Engineering & Technology (VIET)
for offering a supportive environment that made this experience possible. I
extend my sincere appreciation to Dr. G. Satyanarayana, Chairman of VIET,
for his visionary leadership, and Dr. G.V. Pradeep Varma, Principal of VIET,
for his continuous encouragement. I would also like to thank Dr. D. Santha
Rao, Dean of Academics, for his insightful guidance, and Dr. P. Varma,
Training and Placement Officer (TPO), for his efforts in facilitating this
internship. My thanks are also due to Dr. B. Jeevana Rao, Head of the
Department of Electronics and Communication Engineering (ECE), for his
academic support. I am especially grateful to my Project Guide, Mrs. K.
KANTHI KINNERA M. tech, (Ph . D), for her valuable mentorship, constant
encouragement, and expert guidance throughout the internship. Additionally,
I would like to acknowledge the faculty members of the ECE department
whose teachings and support have played a crucial role in my academic
development.

vii
ABSTRACT
Data science encompasses a set of principles, problem definitions, algorithms,
and processes for extracting nonobvious and useful patterns from large data
sets. Many of the elements of data science have been developed in related
fields such as machine learning and data mining. In fact, the terms data
science, machine learning, and data mining are often used interchangeably.
The commonality across these disciplines is a focus on improving decision
making through the analysis of data. However, although data science borrows
from these other fields, it is broader in scope. Machine learning (ML) focuses
on the design and evaluation of algorithms for extracting patterns from data.
Data mining generally deals with the analysis of structured data and often
implies an emphasis on commercial applications. Data science takes all of
these considerations into account but also takes up other challenges, such as
the capturing, cleaning, and transforming of unstructured social media and
web data; the use of big-data technologies to store and process big,
unstructured data sets; and questions related to data ethics and regulation.

viii
CONTENTS
S.NO Name of the Topic/Chapter Page No. From
To

1 Introduction to Artificial Intelligence 1-4


What is AI 1
How AI Works 1
Types of AI 2
Training models of AI 3
Benefits of AI 4
Applications of AI 4
2 Introduction to Data Science 5-8
What is Data Science 5
Where Data Science Needed 5
What is Data, Types of Data 6
How Does a Data Scientist Work 8
Applications Of Data science 8
3 Machine Learning Concepts and Applications 9-10
Why do we need Machine Learning 9
What Makes a Machine learn 9
Benefits of Machine Learning 10
Challenges of Machine Learning 10
4 Introduction to Python for AI & Data Science 11-12
Why python for data science 11
Python Important Features & Interfaces 11
Advantages and disadvantages of python 12
Difference between Python and R Language 12
5 Python Basics and Syntax, Operators & Control 13-23
Statements
Syntax of Python 14
Data Types & Special Characters 15

ix
Operators 17
Strings in Python 19
6 Functions and Scope in Python 24-26
Functions of Python 24
Scopes of python 25
7 Packages & Modules in Python 27-29
8 Exception Handling in Python 30-32
9 Python Data Structures Overview 33-35
10 Lists, Strings, Sets, Tuples, and Dictionaries in 36-39
Python
11 Files and File Handling in Python 40-41
12 Regular Expressions in Python 42-43
13 CONCLUSION 44

x
CHAPTER 1
INTRODUCTION TO AI

Fig1.0

1.1 What is ARTIFICIAL INTELLIGENCE:


Artificial intelligence (AI) is a set of technologies that enable computers to
perform a variety of advanced functions, including the ability to see,
understand and translate spoken and written language, analyse data,
make recommendations, and more.

AI is the backbone of innovation in modern computing, unlocking value


for individuals and businesses. For example, optical character
recognition (OCR) uses AI to extract text and data from images and
documents, turns unstructured content into business-ready structured
data, and unlocks valuable insights. Artificial intelligence is a field of
science concerned with building computers and machines that can
reason, learn, and act in such a way that would normally require human
intelligence or that involves data whose scale exceeds what humans can
analyse.

1.2 HOW AI WORKS:

Fig1.1

1
1.3 Types of Artificial Intelligence:
Artificial intelligence can be organized in several ways, depending on
stages of development or actions being performed.

For instance, four stages of AI development are commonly recognized.

Reactive machines: Limited AI that only reacts to different kinds of


stimuli based on preprogrammed rules. Does not use memory and thus
cannot learn with new data. IBM’s Deep Blue that beat chess champion
Garry Kasparov in 1997 was an example of a reactive machine.

Limited memory: Most modern AI is considered to be limited memory.


It can use memory to improve over time by being trained with new data,
typically through an artificial neural network or other training model.
Deep learning, a subset of machine learning, is considered limited
memory artificial intelligence time

Theory of mind: Theory of mind AI does not currently exist, but


research is ongoing into its possibilities. It describes AI that can
emulate the human mind and has decision-making capabilities equal
to that of a human, including recognizing and remembering emotions
and reacting in social situations as a human would.

Self-aware: A step above theory of mind AI, self-aware AI describes a


mythical machine that is aware of its own existence and has the
intellectual and emotional capabilities of a human. Like theory of mind
AI, self-aware AI does not currently exist.

Fig 1.2

2
1.4 Artificial Intelligence Training Models:
Supervised learning is a machine learning model that maps a specific
input to an output using labelled training data (structured data).

Unsupervised learning is a machine learning model that learns


patterns based on unlabelled data (unstructured data). Unlike
supervised learning, the end result is not known ahead of time. Rather,
the algorithm learns from the data, categorizing it into groups based on
attributes. For instance, unsupervised learning is good at pattern
matching and descriptive modelling.

In addition to supervised and unsupervised learning, a mixed approach


called semi-supervised learning is often employed, where only some of
the data is labelled. In semi-supervised learning, an end result is
known, but the algorithm must figure out how to organize and structure
the data to achieve the desired results.

Fig 1.3

3
1.5 Benefits of AI:

Fig 1.4
1.6 Applications of AI:

Fig 1.5

4
CHAPTER : 2
What is Data Science
Data Science is a combination of multiple disciplines that uses statistics,
data analysis, and machine learning to analyse data and to extract
knowledge and insights from it.

Data Science is about data gathering, analysis and decision-


making.

Data Science is about finding patterns in data, through analysis, and make
future predictions.

 By using Data Science, companies are able to make:


 Better decisions (should we choose A or B)
 Predictive analysis (what will happen next?)
 Pattern discoveries (find pattern, or maybe hidden information in the
data)

2.1 Where is Data Science Needed:


 For route planning: To discover the best routes to ship
 To foresee delays for flight/ship/train etc. (through predictive
analysis)
 To create promotional offers
 To find the best suited time to deliver goods
 To forecast the next years revenue for a company
 To analyse health benefit of training
 To predict who will win elections

Data Science can be applied in nearly every part of a business where data is
available. Examples are:

 Consumer goods
 Stock markets
 Industry
 Politics
 Logistic companies
 E-commerce

2.2 What is Data:


Data is a collection of information.

5
One purpose of Data Science is to structure data, making it
interpretable and easy to work with.

Data can be categorized into two groups:

 Structured data
 Unstructured data

Fig 2.1
2.3 How Does a Data Scientist Work:
A Data Scientist requires expertise in several backgrounds:

 Machine Learning
 Statistics
 Programming (Python or R)
 Mathematics
 Databases

6
Fig 2.2
1. Problem Statement:

No work starts without motivation, Data science is no exception though.


It’s really important to declare or formulate your problem statement
very clearly and precisely. Your whole model and it’s working depend
on your statement. Many scientists consider this as the main and much
important step of Date Science. So, make sure what’s your problem
statement and how well can it add value to business or any other
organization.

2. Data Collection:

After defining the problem statement, the next obvious step is to go in


search of data that you might require for your model. You must do good
research, find all that you need. Data can be in any form i.e.
unstructured or structured. It might be in various forms like videos,
spreadsheets, coded forms, etc. You must collect all these kinds of
sources.

3. Data Cleaning:

As you have formulated your motive and also you did collect your data,
the next step to do is cleaning. Yes, it is! Data cleaning is the most
favourite thing for data scientists to do. Data cleaning is all about the
removal of missing, redundant, unnecessary and duplicate data from
your collection. There are various tools to do so with the help of
programming in either R or Python. It’s totally on you to choose one of
them. Various scientist has their opinion on which to choose. When it
comes to the statistical part, R is preferred over Python, as it has the
privilege of more than 12,000 packages. While python is used as it is
fast, easily accessible and we can perform the same things as we can in
R with the help of various packages.

4. Data Analysis and Exploration:

7
It’s one of the prime things in data science to do and time to get inner
Holmes out. It’s about analysing the structure of data, finding hidden
patterns in them, studying behaviours, visualizing the effects of one
variable over others and then concluding. We can explore the data with
the help of various graphs formed with the help of libraries using any
programming language. In R, GGplot is one of the most famous models
while Matplotlib in Python.

5. Data Modelling:

Once you are done with your study that you have formed from data
visualization, you must start building a hypothesis model such that it
may yield you a good prediction in future. Here, you must choose a good
algorithm that best fit to your model. There different kinds of algorithms
from regression to classification, SVM (Support vector machines),
Clustering, etc. Your model can be of a Machine Learning algorithm.
You train your model with the train data and then test it with test data.
There are various methods to do so. One of them is the K-fold method
where you split your whole data into two parts, one is Train and the
other is test data. On these bases, you train your model.

6. Optimization and Deployment:

You followed each and every step and hence build a model that you feel
is the best fit. But how can you decide how well your model is
performing? This where optimization comes. You test your data and find
how well it is performing by checking its accuracy. In short, you check
the efficiency of the data model and thus try to optimize it for better
accurate prediction. Deployment deals with the launch of your model
and let the people outside there to benefit from that. You can also obtain
feedback from organizations and people to know their need and then to
work more on your model.

2.4 Applications of Data Science:

Fig 2.3

8
CHAPTER : 3
Machine Learning concepts and Applications
Machine learning (ML) allows computers to learn and make decisions without
being explicitly programmed. It involves feeding data into algorithms to
identify patterns and make predictions on new data. Machine learning is used
in various applications, including image and speech recognition, natural
language processing, and recommender systems.

3.1 Why do we need Machine Learning?


Machine Learning algorithm learns from data, trains on patterns, and
solves or predicts complex problems beyond the scope of traditional
programming. It drives better decision-making and tackles intricate
challenges efficiently.

 Solving Complex Business Problems


 Handling Large Volumes of Data
 Automate Repetitive Tasks
 Personalized User Experience
 Self-Improvement in Performance

3.2 What Makes a Machine “Learn”?


A machine “learns” by recognizing patterns and improving its
performance on a task based on data, without being explicitly
programmed.

The process involves:

Data Input: Machines require data (e.g., text, images, numbers) to


analyse.
Algorithms: Algorithms process the data, finding patterns or
relationships.

Model Training: Machines learn by adjusting their parameters based


on the input data using mathematical models.

Feedback Loop: The machine compares predictions to actual outcomes


and corrects errors (via optimization methods like gradient descent).

Experience and Iteration: Repeating this process with more data


improves the machine’s accuracy over time.

Evaluation and Generalization: The model is tested on unseen data


to ensure it performs well on real-world tasks.

9
3.3 Importance of Data in Machine Learning:
Data is the foundation of machine learning (ML). Without quality data,
ML models cannot learn, perform, or make accurate predictions.

 Data provides the examples from which models learn patterns


and relationships.
 High-quality and diverse data improves model accuracy and
generalization.
 Data ensures models understand real-world scenarios and adapt
to practical applications.
 Features derived from data are critical for training models.
 Separate datasets for validation and testing assess how well the
model performs on unseen data.
 Data fuels iterative improvements in ML models through
feedback loops.

Fig 3.0

3.5 Challenges of Machine Learning:

Fig 3.1

10
CHAPTER : 4
PYTHON
Python is a programming language widely used by Data Scientists.

Python has in-built mathematical libraries and functions, making it easier to


calculate mathematical problems and to perform data analysis.

4.1 Why Python for Data Science?


Python is favoured in data science due to its readability, simplicity, and
versatility. Its extensive libraries and frameworks streamline complex
tasks, allowing data scientists to focus on problem-solving rather than
coding intricacies.

Fig 4.1

4.2 Features of Python:

Fig 4.2

11
4.3 Key Libraries and Tools:
NumPy: A fundamental library for numerical operations in Python,
supporting large, multi-dimensional arrays and matrices.

pandas: A powerful library for data manipulation and analysis, offering


data structures like Data Frames to handle structured data efficiently.

Scikit-learn: A comprehensive library for machine learning, providing


simple and efficient data mining and analysis tools.

Matplotlib and Seaborn: Libraries for creating static, animated, and


interactive visualizations, helping to understand data patterns and
trends

Fig 4.3

4.4 Advantages and Disadvantages of Python:

Fig 4.4

12
4.5 Applications of Python:

Fig 4.5

Benefits of Python:

Fig 4.6

4.6 Difference between Python and R Language

Fig 4.7

13
CHAPTER: 5
Python Syntax, Data Types & Operators
Python is known for its clean and readable syntax, which makes it an
excellent language for beginners and professionals working in AI, data
science, and software development.

5.1 Python Syntax


Python syntax refers to the set of rules that define how a Python program is
written and interpreted. One of the most distinctive and beginner-friendly
aspects of Python is its clean and readable syntax. Unlike many other
programming languages that use curly braces {} to define code blocks, Python
uses indentation (whitespace). This means that consistent indentation is not
just a style, but a requirement in Python—usually 4 spaces are used per
indentation level.

A Python program is made up of statements and expressions. Statements are


instructions (like if, for, or def) that perform actions, while expressions are
combinations of values and operators that evaluate to a result. Python is case-
sensitive, so Name, name, and NAME are all treated as different identifiers.

Some key points of Python syntax:

Comments start with # and are ignored by the interpreter. Use them to explain
your code.
Variables do not require a type declaration; the type is inferred from the value
(e.g., x = 10).

Functions are defined using the def keyword, and blocks of code are
structured using colons (:) followed by indented lines.

Control structures like if, elif, else, for, and while are written in a natural,
readable way.

Importing modules is done using the import keyword.

Example:

# This is a comment

def greet(name):

if name:

print (f"Hello, {name}!")

else:

14
print ("Hello, Guest!")

greet("Alice")

Python also supports a REPL (Read-Eval-Print Loop) mode, where you can
type Python code line by line and see immediate results. This makes it great
for quick testing and learning. Overall, Python's syntax emphasizes
readability, simplicity, and consistency, which is why it's so widely loved by
beginners and professionals alike.

Fig 5.1

5.2 Python Data Types:


In Python, data types define the kind of value a variable can hold, and they
are essential for writing correct and efficient programs. Python is a
dynamically typed language, which means you don't need to declare the data
type of a variable explicitly—Python detects it automatically at runtime. The
built-in data types in Python can be broadly categorized into several types:

15
◆ 1. Numeric Types

These include:

int – for integers (e.g., 10, -5)

float – for decimal numbers (e.g., 3.14, -0.01)

complex – for complex numbers (e.g., 2 + 3j)

◆ 2. Sequence Types

These are ordered collections:

str – string, a sequence of characters (e.g., "Hello")

list – mutable sequence of items (e.g., [1, 2, 3])

tuple – immutable sequence (e.g., (4, 5, 6))

◆ 3. Set Types

set – unordered collection of unique items (e.g., {1, 2, 3})

frozen set – like a set but immutable

◆ 4. Mapping Type

dict – a collection of key-value pairs (e.g., {"name": "Alice", "age": 25})

◆ 5. Boolean Type

bool – represents True or False, typically used in conditional expressions

◆ 6. Binary Types

Used to handle binary data:

bytes – immutable sequence of bytes

bytearray – mutable sequence of bytes

memoryview – memory-efficient view of bytes

16
◆ 7. None Type

NoneType – represents the absence of a value, written as None

Example:

a = 10 # int

b = 3.14 # float

c = "Python" # str

d = [1, 2, 3] # list

e = {"key": 1} # dict

f = True # bool

Python also allows you to check the type of a variable using the built-in type()
function, and you can convert between types using type casting, such as int(),
float(), str(), etc. Understanding data types is foundational for writing correct
Python code, as operations and functions behave differently depending on the
type of data they work with.

5.3 Operators:
In Python, operators are special symbols or keywords used to perform
operations on variables and values. Python supports several types of
operators that enable arithmetic operations, comparisons, logical decisions,
bitwise manipulations, and more. These operators make it easier to write
expressions that carry out calculations and control flow in programs.

1. Arithmetic Operators

Used to perform basic mathematical operations:

+ (Addition), - (Subtraction), * (Multiplication), / (Division)

// (Floor Division), % (Modulus), ** (Exponentiation)

Example:

a=5

b=2

print (a + b) # 7

print (a ** b) # 25

2. Comparison (Relational) Operators

17
Used to compare values and return a boolean result:

== (Equal to),!= (Not equal to)

> (Greater than), < (Less than)

>= (Greater than or equal to), <= (Less than or equal to)

Example:

x = 10

y = 20

print (x < y) # True

3. Logical Operators

Used to combine conditional statements:

and – True if both conditions are true

or – True if at least one condition is true

not – Reverses the result (True becomes False)

Example:

a=5

print (a > 2 and a < 10) # True

4. Assignment Operators

Used to assign values to variables:

=, +=, -=, *=, /=, %=, **=, //=

Example:

x=5

x += 3 # x becomes 8

5. Bitwise Operators

Used to perform operations on binary representations:

& (AND), | (OR), ^ (XOR)

~ (NOT), << (Left Shift), >> (Right Shift)

18
Example:

a=5 # 0101

b=3 # 0011

print (a & b) # 1 (0001)

6. Membership Operators

Used to test if a value is a member of a sequence (like list, string, tuple):

in – returns True if value exists

not in – returns True if value does not exist

Example:

fruits = ["apple", "banana"]

print ("apple" in fruits) # True

7. Identity Operators

Used to compare memory locations of objects:

is – returns True if two variables point to the same object

is not – returns True if they do not

Example:

x = [1, 2, 3]

y=x

print (x is y) # True

5.4 Control Statements:


Control statements in Python are used to manage the flow of execution in a
program. They allow you to make decisions, repeat actions, or jump out of
certain code blocks based on conditions. The three main types of control
statements are conditional statements, looping statements, and loop control
statements.

◆ Conditional Statements
These statements let your program make decisions based on certain
conditions. Python uses:

19
if – executes a block if the condition is true

elif – checks another condition if the previous one was false

else – executes a block if all previous conditions were false

Example:

x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

◆ Looping Statements
Loops are used to repeat a block of code multiple times.

for loop – iterates over a sequence (like a list, string, or range)

while loop – repeats as long as a condition is true

Examples:

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

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

◆ Loop Control Statements


These are used to alter the flow inside loops:

break – exits the loop immediately

continue – skips the rest of the current iteration

20
pass – does nothing, used as a placeholder

Example:

for i in range (5):


if i == 3:
break
print(i) # prints 0, 1, 2

for i in range (5):


if i == 3:
continue
print(i) # prints 0, 1, 2, 4
Control statements are the backbone of decision-making and repetition in
Python, making it possible to write intelligent, responsive, and efficient
programs.

5.4 Strings in Python:


Strings in Python

In Python, a string is a sequence of characters used to represent textual data


such as words, sentences, or even numbers written as text. Strings are
enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """) for
multi-line strings. Python strings are immutable, meaning once a string is
created, its characters cannot be changed individually—you can only create a
new string through operations. Strings support a variety of operations like
concatenation, slicing, and iteration, and are widely used in almost every
Python program.

Python offers many powerful string methods to work with text, such as:

upper () – converts to uppercase

lower () – converts to lowercase

title () – capitalizes each word

21
strip () – removes whitespace from both ends

replace (old, new) – replaces parts of the string

split () – splits the string into a list

join () – joins elements of a list into a single string

find () – returns the index of the first match

startswith () / endswith () – checks how a string begins or ends

Example:

text = “Python is awesome! “

print(text.strip().upper()) # Output: PYTHON IS AWESOME!

Strings can also be indexed and sliced:

word = "Python"

print(word[0]) # P (first character)

print(word[-1]) # n (last character)

print (word [1:4]) # yth (slicing from index 1 to 3)

Python also supports string formatting, which allows you to embed variables
into strings:

Using f-strings: f"Hello, {name}!"

Using .format(): "Hello, {}”. format(name)

Using % formatting (older style): "Hello, %s" % name

A string is a sequence of characters which is enclosed in quotes.

22
There are basically 3 types of operators supported by string:

 Basic Operators: There are two types of basic operators in string. They are
“+” and “*”.
1. Concatenation Operator (+): the concatenation operator concatenates
two strings and forms a new string.
2. Replication Operator (*): It is used to repeat a string number of times
the string will be repeated the number of times is given by the integer
value.
 Membership operators: To test whether a value is present in a sequence.
 Relational Operators: All the comparisons operators i.e., (<,>, <=,>=, == ,!=,
<>)
 Slice Notation: String Slice can be defined as substring which is the part of
string. Therefore, further substring can be obtained from a string.

Strings in Python are versatile and essential, used in everything from simple
output messages to file handling, data parsing, and user input. Their
flexibility and the wide range of methods make them one of the most
important data types in Python.

23
CHAPTER:6
Functions and Scope in Python
In Python: functions, modules, and exception handling. These concepts help
developers write organized, reusable, and error-free code, making Python a
powerful and efficient programming language for AI, data science, and
software development.

6.1 Functions in Python:


Functions in Python

In Python, a function is a reusable block of code that performs a specific task.


Functions help organize code, make it more readable, reduce repetition, and
allow for modular programming. You can define a function using the def
keyword, followed by the function name and parentheses (), which may
include parameters—placeholders for the inputs the function can receive. The
code inside the function is indented and runs only when the function is called.
If a function should return a result, you use the return statement. In

• Built-in Functions such as print (), len (), and range ().

• User-defined Functions, where programmers create their own functions


using the def

keyword.

• Function Parameters and Return Values, enabling functions to accept


input and return

output for better flexibility.

• Lambda Functions, which are small anonymous functions used for quick,
short operations.

Example:

def greet(name):

return f"Hello, {name}!"

print(greet("Alice")) # Output: Hello, Alice!

Python also supports default arguments, where parameters can have default
values:

24
python

Copy

Edit

def greet(name="Guest"):

print (f"Welcome, {name}!")

Functions can take any number of arguments using:

*args for variable-length positional arguments

**kwargs for variable-length keyword arguments

Python also allows anonymous functions using the lambda keyword. These
are short, one-line functions used for simple tasks, especially with functions
like map (), filter (), and sorted ().

Example:

square = lambda x: x * x

print (square (5)) # Output: 25

6.2 Scopes of Python


In Python, scope refers to the visibility and accessibility of variables
within different parts of a program. Scope determines where a variable
is accessible and where not. In order to understand how variables
behave within functions and how they interact with each other, it is
crucial to understand scope.

Python has two main types of scope:

Local scope:
 Variables declared within a function have local scope. They are
accessible only within the function in which they are defined.
 Local variables are created when the function is called and
destroyed when it exits.
 Local variables cannot be accessed from outside the function.

25
Global Scope:
 Variables declared outside of any function or at the top level of a
script have global scope. They are accessible throughout the
program.
 During program startup, global variables are created in memory
and remain there until the program ends.
 Global variables can be accessed from any function within the
program.

Nested scope:
 Python allows nested functions, where one function is defined
inside another.
 During nested functions, the inner function has access to
variables in the outer (enclosed) function.
 The inner function's scope is called "nested scope" because it
includes both its local scope and the enclosing function's scope.

26
CHAPTER: 7
Packages and Modules in Python
Introduction
Python is a high-level, general-purpose programming language widely used in
various domains including data science, machine learning, web development,
and automation. One of Python’s key strengths is its modular structure,
which allows developers to organize code into reusable components. This
modularity is achieved through the use of modules and packages, which play
a vital role in organizing, maintaining, and scaling Python projects effectively.

Modules in Python
A module is a file containing Python code that is written for reuse. It typically
consists of functions, classes, and variables that serve specific functionalities.
The primary goal of a module is to break down large programs into smaller,
manageable, and logically organized parts. This enhances code readability,
promotes reuse, and simplifies debugging and maintenance.

Modules form the foundational building blocks of Python programs. They can
be standard (built-in to Python), third-party (installed externally), or user-
defined (created by the developer). Using modules also allows for separation
of concerns, where each module is responsible for a specific part of the
program logic, reducing complexity in large codebases.

27
Packages in Python
A package is a hierarchical file structure that contains multiple modules
grouped together to form a collection of related functionalities. Packages allow
developers to organize their modules into directories, thereby creating a
scalable project structure. The presence of a special initialization file in the
directory indicates to Python that it should treat the directory as a package.

Packages are essential when working on large projects that involve multiple
components. By categorizing similar modules into packages, developers can
avoid naming conflicts, improve code organization, and enable better
navigation through the codebase. Packages can also contain sub-packages,
allowing for multi-level structuring of code.

Advantages of Using Modules and Packages

The use of modules and packages provides several benefits in software


development:

 Reusability: Code can be written once and reused in different


programs.

 Maintainability: Issues can be isolated and fixed within individual


modules or packages.

 Readability: Well-structured code is easier to understand and modify.

 Namespace Management: Helps avoid conflicts by isolating function


and variable names.

 Scalability: Supports growth of codebase in an organized manner,


especially in large projects.

In professional environments, especially in domains like data science,


modular programming with well-organized packages and modules is
considered a best practice.

Relevance in Data Science


In the field of data science, modular code organization is crucial due to the
multifaceted nature of tasks such as data preprocessing, analysis,
visualization, and model evaluation. Data scientists frequently work with
various Python packages designed for specific tasks. Understanding the
structure and use of modules and packages enables data scientists to build
efficient, reusable, and well-organized code pipelines.

During the course of my internship in the domain of data science, I learned


the importance of modular programming when dealing with data workflows.
The use of packages and modules made it easier to manage code, automate

28
repetitive processes, and collaborate effectively in a team environment. This
approach not only improved the quality of the code but also enhanced overall
productivity.
Modules in Python are essential components that allow programmers to
organize code into separate files and reuse functionality across different
programs. A module is simply a file containing Python code—such as
functions, classes, or variables—that can be imported and used in another
Python script. Python supports various types of modules, including built-in
modules like math, os, and datetime, which come pre-installed and provide
powerful features for mathematical operations, file handling, and date/time
manipulation. Users can also create their own custom modules, known as
user-defined modules, to structure their code better and enhance reusability.
Additionally, third-party modules like numpy, pandas, matplotlib, and flask
can be installed using Python’s package manager pip to perform specific tasks
such as data analysis, visualization, and web development. Modules can be
imported using the import statement, and specific functions or classes can be
brought in using from module import name. By using modules, Python
promotes modular programming, which leads to cleaner, more manageable
code, encourages reusability, reduces redundancy, and improves overall
program structure. Whether for small scripts or large applications, modules
play a vital role in efficient and effective Python development.

29
CHAPTER: 8
EXCEPTION HANDLING IN PYTHON
Introduction
In any programming language, errors are a natural part of the development
process. Python provides a structured way to detect and handle these errors
using a mechanism called exception handling. This allows programs to
respond to unexpected situations without crashing, thereby improving
robustness, user experience, and overall software reliability.

Exception handling is a critical concept in Python, particularly in data-driven


applications where unpredictable user input, file errors, or network issues
can arise. Effective handling of exceptions ensures smooth execution and
helps in debugging, logging, and maintaining code efficiently.

Understanding Exceptions
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions are not necessarily errors
in logic; they often result from conditions that are beyond the control of the
program, such as attempting to access a file that does not exist or dividing a
number by zero.

In Python, exceptions are objects that represent these error conditions. When
an exception occurs, Python immediately stops the current flow of the
program and looks for a way to handle the exception. If not handled, the
program terminates and displays an error message, commonly referred to as
a traceback.

Exception Handling Mechanism


Python uses a structured approach to manage exceptions through specific
keywords that help detect and respond to exceptions. The handling
mechanism allows developers to define blocks of code to try and detect errors,
and to define alternative behaviours in case an error occurs. This approach
separates normal program logic from error handling, which leads to clearer
and more maintainable code.

The exception handling structure in Python includes the following:

 A block to attempt execution.

 One or more blocks to handle specific or general exceptions.

 An optional block that executes regardless of whether an exception


occurred.

30
 An optional block for cleanup actions.

This mechanism provides flexibility and control over how different types of
exceptions are managed and ensures that the program can continue running
or exit gracefully.

Benefits of Exception Handling


Proper use of exception handling brings multiple benefits to Python programs,
especially in complex or user-facing applications. Some key advantages
include:

 Error Isolation: Helps identify exactly where the error occurred without
affecting the rest of the code.

 Improved User Experience: Allows for graceful failure and user-friendly


error messages instead of program crashes.

 Code Clarity: Separates normal program logic from error handling,


making code cleaner and easier to understand.

 System Stability: Prevents unexpected terminations by managing rare


or unanticipated situations safely.

 Maintenance & Debugging: Makes the program easier to maintain and


debug by providing detailed error messages and control flow.

Exception Hierarchy and Custom Exceptions


Python’s built-in exception classes are arranged in a hierarchy, starting from
a base class. This structure allows developers to catch a broad category of
errors or target specific ones. Additionally, Python allows developers to define
their own custom exceptions by creating new classes. This is especially useful
in larger projects, including data science applications, where domain-specific
errors need to be clearly identified and handled.

Custom exception handling improves code readability and gives a clearer


understanding of how certain errors are treated uniquely, contributing to
better error tracking and documentation.

Relevance in Data Science


In the domain of data science, exception handling is crucial due to the
unpredictability of data sources and system resources. Whether it is reading
from external files, processing real-time data, or interacting with APIs,
exceptions can occur at multiple stages. Proper handling ensures that data
pipelines do not break due to a single failure and that logs are maintained for
future analysis.

31
During my internship in the field of data science, I encountered several
scenarios where exception handling became necessary—for instance, when
handling missing values, managing file loading issues, or connecting to
external databases. Implementing structured exception handling helped me
build resilient scripts that could run reliably in different environments with
varying data inputs.

Conclusion
Exception handling is a fundamental aspect of writing robust and
professional-grade Python applications. It allows developers to anticipate and
manage errors effectively, ensuring that programs behave predictably even
under unexpected conditions. In data science and other real-world
applications, the ability to handle exceptions gracefully not only improves
performance but also enhances the reliability and trustworthiness of the
system. My internship experience underscored the importance of mastering
exception handling to create stable, scalable, and user-friendly Python
solutions.

32
CHAPTER: 9
PYTHON DATA STRCTURES
Introduction
Data structures are the foundational building blocks of any programming
language. In Python, data structures are used to store, organize, and manage
data efficiently. They provide a means of performing operations on data and
are essential for solving complex computational problems. Python offers a rich
collection of built-in data structures that are both flexible and easy to use,
which makes the language especially powerful for data science and software
development.

Understanding and utilizing Python’s data structures effectively is crucial for


writing optimized and maintainable code. They support efficient data
manipulation, enable clear program logic, and allow for better performance
across a wide range of applications.

Types of Data Structures in Python


Python provides several built-in data structures, each with unique properties,
performance characteristics, and use cases. These can be categorized into two
main types: primitive and non-primitive data structures.

1. Primitive Data Structures

These are the most basic data types in Python, including:

 Integers

 Floats

 Strings

 Booleans
While not considered data structures in the traditional sense, these primitives
form the basis for more complex types.

2. Non-Primitive Data Structures

These include more advanced structures that are capable of storing multiple
elements and performing operations on them. The primary non-primitive data
structures in Python are:

 Lists: Ordered and mutable collections of elements.

 Tuples: Ordered but immutable sequences.

 Sets: Unordered collections of unique elements.

33
 Dictionaries: Key-value pairs for efficient lookup and storage.

Each of these structures is implemented in a way that allows for dynamic


memory management, and they can grow or shrink as needed, which makes
them more flexible than traditional arrays in other languages.

Importance in Programming and Data Science


Efficient use of data structures is essential for solving real-world problems.
They help in organizing data logically and performing operations such as
insertion, deletion, traversal, and searching in a time-efficient manner.
In the context of data science, choosing the right data structure can greatly
impact the performance and scalability of data pipelines and analytical
models. For example, dictionaries are often used for mapping categorical
variables, while lists and tuples are commonly used for storing data records
or feature sets.

Python’s built-in data structures are often used in combination with third-
party libraries like pandas, which extends their functionality for handling
structured data such as tables and time series.

Key Features of Python Data Structures


 Dynamic Typing: Python data structures can hold mixed data types,
adding flexibility during implementation.

 Memory Efficiency: Python manages memory dynamically, which


simplifies development while still allowing efficient performance.

 Ease of Use: The syntax and operations associated with Python’s data
structures are intuitive and user-friendly.

 Rich Functionality: Python provides a wide range of built-in methods


for manipulating data structures, enhancing productivity and code
readability.

 Extensibility: Built-in structures can be extended or customized to


create more complex structures such as stacks, queues, and graphs
using object-oriented programming.

Applications in Real-World Projects


During the course of my internship in data science, I worked with large and
complex datasets requiring structured organization and efficient data
manipulation. Python data structures played a key role in managing this data
effectively.

34
Tasks such as data cleaning, transformation, and aggregation were greatly
facilitated by using dictionaries, lists, and sets. Understanding the underlying
structure of data allowed me to implement faster and more reliable solutions,
especially when dealing with large-scale operations or real-time data.

Data structures also supported integration with various tools and libraries,
enabling seamless development of end-to-end data workflows.

35
Chapter:10
Lists, Tuples, Sets, Dictionaries and Strings in
Python
List
A list in Python is a dynamic, ordered collection that can store elements of
different data types such as integers, floats, strings, or even other lists (nested
lists). Lists are mutable, so you can change, add, or delete elements without
creating a new list. They are defined using square brackets []. Lists are
versatile and widely used for storing a sequence of items such as a list of
student names, shopping items, or daily temperatures.

Common methods include:

 append () – adds an item to the end

 insert () – inserts an item at a specific index

 pop () – removes and returns the last element

 sort () – sorts the list in ascending order

 reverse () – reverses the list

Example:

fruits = ["apple", "banana", "cherry"]


fruits. Append("orange")

print(fruits)

Output = ['apple', 'banana', 'cherry', 'orange']

String
A string is a sequence of Unicode characters used to represent text. Strings
are immutable, meaning once created, their content cannot be changed. You
can perform various operations on strings like slicing, searching, formatting,
and joining. Strings are defined using single ' or double " quotes, and multiline
strings use triple quotes ''' or """.

Common methods include:

 upper () – converts to uppercase

 lower () – converts to lowercase

 find () – finds a substring

36
 replace () – replaces part of the string

 split () – splits the string into a list

Example:

python

message = "Python is fun"

print (message. Upper ())

Output = PYTHON IS FUN

Tuple
A tuple is a collection similar to a list but immutable, meaning once it's
created, you cannot add, remove, or change elements. Tuples are defined
using parentheses (). Because they are immutable, they can be used as
dictionary keys or elements in a set, which lists cannot do. Tuples are
usually used when the data should not be changed throughout the program,
like coordinates (x, y) or months of the year.

Common operations:

 Accessing elements via index

 Iterating with loops

 Using count () and index () methods

Example:

python

dimensions = (10, 20, 30)

print (dimensions [1])

Output = 20

Advantages:

 Faster than lists (since immutable)

 Safer for storing fixed data

Dictionary
A dictionary is an unordered, mutable collection of key-value pairs. Each
key must be unique and immutable (like strings, numbers, or tuples).
Dictionaries are written using curly braces {}. They are commonly used to
store data like student records, configurations, or any structured data.

37
Common methods:

 get () – safely gets a value by key

 keys () – returns all keys

 values () – returns all values

 items () – returns all key-value pairs

 update () – updates the dictionary with another dictionary

Example:

python

student = {"name": "Alice", "age": 20, "grade": "A"}

print(student["name"])

Output = Alice

Use Cases:

 Storing structured data (e.g., JSON-like)

 Fast lookups based on keys

 Grouping related values together

Set
A set is a collection of unordered, unique items. Sets are useful when you
want to ensure there are no duplicate entries. Sets are mutable, meaning you
can add or remove elements, but they do not support indexing or slicing
because they are unordered. Sets are ideal for operations like union,
intersection, and difference between groups.

Common methods:

 add () – adds an element

 remove () – removes an element

 union () – combines two sets

 intersection () – finds common elements

 difference () – elements in one set but not another

Example:

python

set1 = {1, 2, 3}

38
set2 = {3, 4, 5}

print (set1 & set2)

Output = {3}

39
Chapter: 11
Files and File Handling in Python
Files and File Handling in Python
In Python, file handling allows you to create, read, write, and delete files
directly from your Python program. This is especially useful when you want
to store data permanently, process text files, or interact with external files like
logs, reports, or configurations. Python provides built-in functions for file
handling, and the most common one is the open () function. This function is
used to open a file and returns a file object, which lets you perform various
operations on the file.

When opening a file, you must specify the mode:

 "r" – Read (default mode; file must exist)

 "w" – Write (creates a new file or overwrites if it exists)

 "a" – Append (adds data to the end of the file)

 "x" – Create (creates a file, returns error if file exists)

 Add "b" for binary mode (e.g., "rb" for read binary)

 Add "+" to read and write ("r+", "w+", etc.)

To read data from a file, you can use:

 read () – reads the entire file as a string

 readline () – reads one line at a time

 readlines () – reads all lines and returns a list

To write to a file, use write () or writelines (). After you're done working with a
file, it’s important to close it using close () to free up system resources.
However, the better way to handle files in Python is using a with block (also
called a context manager), which automatically closes the file when done.
Example (writing and reading a file):

python

# Writing to a file

with open ("example.txt", "w") as file:

file.write ("Hello, this is a test file.\n")

file.write("Python is fun!")

40
# Reading from a file

with open ("example.txt", "r") as file:

content = file.read()

print(content)

Advantages of Python's file handling include simplicity, cross-platform


compatibility, and powerful tools for both text and binary file operations. It is
widely used in data processing, saving logs, creating reports, and handling
user inputs.

41
Chapter: 12
Regular Expressions in Python
Regular Expressions (commonly abbreviated as RegEx) are powerful tools
used in Python to search, match, and manipulate strings based on specific
patterns. They are especially useful when you need to validate input (like
emails or phone numbers), extract specific parts of text, or perform complex
text replacements. Python provides the re module for working with regular
expressions. To use it, you must import it with import re.

At the core of regular expressions are patterns made up of special


characters. Some common ones include:

 . – matches any character except newline

 ^ – matches the start of a string

 $ – matches the end of a string

 * – matches 0 or more repetitions

 + – matches 1 or more repetitions

 ? – matches 0 or 1 repetition

 [] – matches any one character inside the brackets

 \d – matches any digit (0-9)

 \w – matches any alphanumeric character

 \s – matches any whitespace character

Common functions in the re module:


 re.match () – checks for a match only at the beginning of a string

 re.search() – searches the whole string for the first match

 re.findall() – returns all non-overlapping matches as a list

 re.sub() – replaces matched patterns with a new string

 re.compile() – compiles a regular expression pattern for reuse

Example:

python

import re

42
CERTIFICATE

This is to certify that the INTERNSHIP report entitled PYTHON COURSE is


being submitted by YALLAPU ANAND – 21NT1A0458 In partial fulfillment for
the award of the Degree of Bachelor of Technology in Electronics &
Communication Engineering to the Jawaharlal Nehru Technological University,
Gurajada Vizianagaram is a record of bonafied work carried out under my
guidance and supervision. The results embodied in this INTERNSHIP report
have not been submitted to any other University or Institute for the award of
any Degree or Diploma.

Signature of the Guide Signature of the HOD

Dr. B. Jeevana Rao

Assistant Professor Associate Professor

Department of ECE Department of ECE

EXTERNAL EXAMINER

iii
ACCEPTANCE LETTER FROM SKILLDZIRE
ORGANIZATION

iv
CERTIFICATE FROM INTERN ORGANIZATION

v
DECLARATION

I hereby declare that the work presented in this report titled


"PYTHON COURSE Internship Report" is the result of my own
research and study during the internship period at
SKILLDZIRE, undertaken from 16-DEC-2024 to 12-APR-2025.
This report is being submitted in partial fulfilment of the
requirements for the completion of my B.TECH, VISAKHA
INSTITUTE OF ENGINEERING AND
TECHNOLOGY
AFFLIATED TO JNTUGV. All the information, data and results
included in this report are genuine and have been collected,
analyzed, and interpreted by me. Any references or
contributions made by other authors or researchers have
been duly acknowledged in the form of citations and
references. I also confirm that this report has not been
submitted elsewhere for the award of any degree, diploma, or
certificate.

Place: Visakhapatnam Y. ANAND

Date: (21NT1A0458)

vi
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have
supported and guided me throughout my Python Course internship. My
heartfelt thanks to Skill Dzire Organization for providing me with the
opportunity to work and enhance my skills in the field of Python course. I am
deeply thankful to Visakha Institute of Engineering & Technology (VIET)
for offering a supportive environment that made this experience possible. I
extend my sincere appreciation to Dr. G. Satyanarayana, Chairman of VIET,
for his visionary leadership, and Dr. G.V. Pradeep Varma, Principal of VIET,
for his continuous encouragement. I would also like to thank Dr. D. Santha
Rao, Dean of Academics, for his insightful guidance, and Dr. P. Varma,
Training and Placement Officer (TPO), for his efforts in facilitating this
internship. My thanks are also due to Dr. B. Jeevana Rao, Head of the
Department of Electronics and Communication Engineering (ECE), for his
academic support. I am especially grateful to my Project Guide, Mrs. K.
KANTHI KINNERA M. tech, (Ph . D), for her valuable mentorship, constant
encouragement, and expert guidance throughout the internship. Additionally,
I would like to acknowledge the faculty members of the ECE department
whose teachings and support have played a crucial role in my academic
development.

vii
ABSTRACT
Data science encompasses a set of principles, problem definitions, algorithms,
and processes for extracting nonobvious and useful patterns from large data
sets. Many of the elements of data science have been developed in related
fields such as machine learning and data mining. In fact, the terms data
science, machine learning, and data mining are often used interchangeably.
The commonality across these disciplines is a focus on improving decision
making through the analysis of data. However, although data science borrows
from these other fields, it is broader in scope. Machine learning (ML) focuses
on the design and evaluation of algorithms for extracting patterns from data.
Data mining generally deals with the analysis of structured data and often
implies an emphasis on commercial applications. Data science takes all of
these considerations into account but also takes up other challenges, such as
the capturing, cleaning, and transforming of unstructured social media and
web data; the use of big-data technologies to store and process big,
unstructured data sets; and questions related to data ethics and regulation.

viii
CONTENTS
S.NO Name of the Topic/Chapter Page No. From
To

1 Introduction to Artificial Intelligence 1-4


What is AI 1
How AI Works 1
Types of AI 2
Training models of AI 3
Benefits of AI 4
Applications of AI 4
2 Introduction to Data Science 5-8
What is Data Science 5
Where Data Science Needed 5
What is Data, Types of Data 6
How Does a Data Scientist Work 8
Applications Of Data science 8
3 Machine Learning Concepts and Applications 9-10
Why do we need Machine Learning 9
What Makes a Machine learn 9
Benefits of Machine Learning 10
Challenges of Machine Learning 10
4 Introduction to Python for AI & Data Science 11-12
Why python for data science 11
Python Important Features & Interfaces 11
Advantages and disadvantages of python 12
Difference between Python and R Language 12
5 Python Basics and Syntax, Operators & Control 13-23
Statements
Syntax of Python 14
Data Types & Special Characters 15

ix
Operators 17
Strings in Python 19
6 Functions and Scope in Python 24-26
Functions of Python 24
Scopes of python 25
7 Packages & Modules in Python 27-29
8 Exception Handling in Python 30-32
9 Python Data Structures Overview 33-35
10 Lists, Strings, Sets, Tuples, and Dictionaries in 36-39
Python
11 Files and File Handling in Python 40-41
12 Regular Expressions in Python 42-43
13 CONCLUSION 44

x
CHAPTER 1
INTRODUCTION TO AI

Fig1.0

1.1 What is ARTIFICIAL INTELLIGENCE:


Artificial intelligence (AI) is a set of technologies that enable computers to
perform a variety of advanced functions, including the ability to see,
understand and translate spoken and written language, analyse data,
make recommendations, and more.

AI is the backbone of innovation in modern computing, unlocking value


for individuals and businesses. For example, optical character
recognition (OCR) uses AI to extract text and data from images and
documents, turns unstructured content into business-ready structured
data, and unlocks valuable insights. Artificial intelligence is a field of
science concerned with building computers and machines that can
reason, learn, and act in such a way that would normally require human
intelligence or that involves data whose scale exceeds what humans can
analyse.

1.2 HOW AI WORKS:

Fig1.1

1
1.3 Types of Artificial Intelligence:
Artificial intelligence can be organized in several ways, depending on
stages of development or actions being performed.

For instance, four stages of AI development are commonly recognized.

Reactive machines: Limited AI that only reacts to different kinds of


stimuli based on preprogrammed rules. Does not use memory and thus
cannot learn with new data. IBM’s Deep Blue that beat chess champion
Garry Kasparov in 1997 was an example of a reactive machine.

Limited memory: Most modern AI is considered to be limited memory.


It can use memory to improve over time by being trained with new data,
typically through an artificial neural network or other training model.
Deep learning, a subset of machine learning, is considered limited
memory artificial intelligence time

Theory of mind: Theory of mind AI does not currently exist, but


research is ongoing into its possibilities. It describes AI that can
emulate the human mind and has decision-making capabilities equal
to that of a human, including recognizing and remembering emotions
and reacting in social situations as a human would.

Self-aware: A step above theory of mind AI, self-aware AI describes a


mythical machine that is aware of its own existence and has the
intellectual and emotional capabilities of a human. Like theory of mind
AI, self-aware AI does not currently exist.

Fig 1.2

2
1.4 Artificial Intelligence Training Models:
Supervised learning is a machine learning model that maps a specific
input to an output using labelled training data (structured data).

Unsupervised learning is a machine learning model that learns


patterns based on unlabelled data (unstructured data). Unlike
supervised learning, the end result is not known ahead of time. Rather,
the algorithm learns from the data, categorizing it into groups based on
attributes. For instance, unsupervised learning is good at pattern
matching and descriptive modelling.

In addition to supervised and unsupervised learning, a mixed approach


called semi-supervised learning is often employed, where only some of
the data is labelled. In semi-supervised learning, an end result is
known, but the algorithm must figure out how to organize and structure
the data to achieve the desired results.

Fig 1.3

3
1.5 Benefits of AI:

Fig 1.4
1.6 Applications of AI:

Fig 1.5

4
CHAPTER : 2
What is Data Science
Data Science is a combination of multiple disciplines that uses statistics,
data analysis, and machine learning to analyse data and to extract
knowledge and insights from it.

Data Science is about data gathering, analysis and decision-


making.

Data Science is about finding patterns in data, through analysis, and make
future predictions.

 By using Data Science, companies are able to make:


 Better decisions (should we choose A or B)
 Predictive analysis (what will happen next?)
 Pattern discoveries (find pattern, or maybe hidden information in the
data)

2.1 Where is Data Science Needed:


 For route planning: To discover the best routes to ship
 To foresee delays for flight/ship/train etc. (through predictive
analysis)
 To create promotional offers
 To find the best suited time to deliver goods
 To forecast the next years revenue for a company
 To analyse health benefit of training
 To predict who will win elections

Data Science can be applied in nearly every part of a business where data is
available. Examples are:

 Consumer goods
 Stock markets
 Industry
 Politics
 Logistic companies
 E-commerce

2.2 What is Data:


Data is a collection of information.

5
One purpose of Data Science is to structure data, making it
interpretable and easy to work with.

Data can be categorized into two groups:

 Structured data
 Unstructured data

Fig 2.1
2.3 How Does a Data Scientist Work:
A Data Scientist requires expertise in several backgrounds:

 Machine Learning
 Statistics
 Programming (Python or R)
 Mathematics
 Databases

6
Fig 2.2
1. Problem Statement:

No work starts without motivation, Data science is no exception though.


It’s really important to declare or formulate your problem statement
very clearly and precisely. Your whole model and it’s working depend
on your statement. Many scientists consider this as the main and much
important step of Date Science. So, make sure what’s your problem
statement and how well can it add value to business or any other
organization.

2. Data Collection:

After defining the problem statement, the next obvious step is to go in


search of data that you might require for your model. You must do good
research, find all that you need. Data can be in any form i.e.
unstructured or structured. It might be in various forms like videos,
spreadsheets, coded forms, etc. You must collect all these kinds of
sources.

3. Data Cleaning:

As you have formulated your motive and also you did collect your data,
the next step to do is cleaning. Yes, it is! Data cleaning is the most
favourite thing for data scientists to do. Data cleaning is all about the
removal of missing, redundant, unnecessary and duplicate data from
your collection. There are various tools to do so with the help of
programming in either R or Python. It’s totally on you to choose one of
them. Various scientist has their opinion on which to choose. When it
comes to the statistical part, R is preferred over Python, as it has the
privilege of more than 12,000 packages. While python is used as it is
fast, easily accessible and we can perform the same things as we can in
R with the help of various packages.

4. Data Analysis and Exploration:

7
It’s one of the prime things in data science to do and time to get inner
Holmes out. It’s about analysing the structure of data, finding hidden
patterns in them, studying behaviours, visualizing the effects of one
variable over others and then concluding. We can explore the data with
the help of various graphs formed with the help of libraries using any
programming language. In R, GGplot is one of the most famous models
while Matplotlib in Python.

5. Data Modelling:

Once you are done with your study that you have formed from data
visualization, you must start building a hypothesis model such that it
may yield you a good prediction in future. Here, you must choose a good
algorithm that best fit to your model. There different kinds of algorithms
from regression to classification, SVM (Support vector machines),
Clustering, etc. Your model can be of a Machine Learning algorithm.
You train your model with the train data and then test it with test data.
There are various methods to do so. One of them is the K-fold method
where you split your whole data into two parts, one is Train and the
other is test data. On these bases, you train your model.

6. Optimization and Deployment:

You followed each and every step and hence build a model that you feel
is the best fit. But how can you decide how well your model is
performing? This where optimization comes. You test your data and find
how well it is performing by checking its accuracy. In short, you check
the efficiency of the data model and thus try to optimize it for better
accurate prediction. Deployment deals with the launch of your model
and let the people outside there to benefit from that. You can also obtain
feedback from organizations and people to know their need and then to
work more on your model.

2.4 Applications of Data Science:

Fig 2.3

8
CHAPTER : 3
Machine Learning concepts and Applications
Machine learning (ML) allows computers to learn and make decisions without
being explicitly programmed. It involves feeding data into algorithms to
identify patterns and make predictions on new data. Machine learning is used
in various applications, including image and speech recognition, natural
language processing, and recommender systems.

3.1 Why do we need Machine Learning?


Machine Learning algorithm learns from data, trains on patterns, and
solves or predicts complex problems beyond the scope of traditional
programming. It drives better decision-making and tackles intricate
challenges efficiently.

 Solving Complex Business Problems


 Handling Large Volumes of Data
 Automate Repetitive Tasks
 Personalized User Experience
 Self-Improvement in Performance

3.2 What Makes a Machine “Learn”?


A machine “learns” by recognizing patterns and improving its
performance on a task based on data, without being explicitly
programmed.

The process involves:

Data Input: Machines require data (e.g., text, images, numbers) to


analyse.
Algorithms: Algorithms process the data, finding patterns or
relationships.

Model Training: Machines learn by adjusting their parameters based


on the input data using mathematical models.

Feedback Loop: The machine compares predictions to actual outcomes


and corrects errors (via optimization methods like gradient descent).

Experience and Iteration: Repeating this process with more data


improves the machine’s accuracy over time.

Evaluation and Generalization: The model is tested on unseen data


to ensure it performs well on real-world tasks.

9
3.3 Importance of Data in Machine Learning:
Data is the foundation of machine learning (ML). Without quality data,
ML models cannot learn, perform, or make accurate predictions.

 Data provides the examples from which models learn patterns


and relationships.
 High-quality and diverse data improves model accuracy and
generalization.
 Data ensures models understand real-world scenarios and adapt
to practical applications.
 Features derived from data are critical for training models.
 Separate datasets for validation and testing assess how well the
model performs on unseen data.
 Data fuels iterative improvements in ML models through
feedback loops.

Fig 3.0

3.5 Challenges of Machine Learning:

Fig 3.1

10
CHAPTER : 4
PYTHON
Python is a programming language widely used by Data Scientists.

Python has in-built mathematical libraries and functions, making it easier to


calculate mathematical problems and to perform data analysis.

4.1 Why Python for Data Science?


Python is favoured in data science due to its readability, simplicity, and
versatility. Its extensive libraries and frameworks streamline complex
tasks, allowing data scientists to focus on problem-solving rather than
coding intricacies.

Fig 4.1

4.2 Features of Python:

Fig 4.2

11
4.3 Key Libraries and Tools:
NumPy: A fundamental library for numerical operations in Python,
supporting large, multi-dimensional arrays and matrices.

pandas: A powerful library for data manipulation and analysis, offering


data structures like Data Frames to handle structured data efficiently.

Scikit-learn: A comprehensive library for machine learning, providing


simple and efficient data mining and analysis tools.

Matplotlib and Seaborn: Libraries for creating static, animated, and


interactive visualizations, helping to understand data patterns and
trends

Fig 4.3

4.4 Advantages and Disadvantages of Python:

Fig 4.4

12
4.5 Applications of Python:

Fig 4.5

Benefits of Python:

Fig 4.6

4.6 Difference between Python and R Language

Fig 4.7

13
CHAPTER: 5
Python Syntax, Data Types & Operators
Python is known for its clean and readable syntax, which makes it an
excellent language for beginners and professionals working in AI, data
science, and software development.

5.1 Python Syntax


Python syntax refers to the set of rules that define how a Python program is
written and interpreted. One of the most distinctive and beginner-friendly
aspects of Python is its clean and readable syntax. Unlike many other
programming languages that use curly braces {} to define code blocks, Python
uses indentation (whitespace). This means that consistent indentation is not
just a style, but a requirement in Python—usually 4 spaces are used per
indentation level.

A Python program is made up of statements and expressions. Statements are


instructions (like if, for, or def) that perform actions, while expressions are
combinations of values and operators that evaluate to a result. Python is case-
sensitive, so Name, name, and NAME are all treated as different identifiers.

Some key points of Python syntax:

Comments start with # and are ignored by the interpreter. Use them to explain
your code.
Variables do not require a type declaration; the type is inferred from the value
(e.g., x = 10).

Functions are defined using the def keyword, and blocks of code are
structured using colons (:) followed by indented lines.

Control structures like if, elif, else, for, and while are written in a natural,
readable way.

Importing modules is done using the import keyword.

Example:

# This is a comment

def greet(name):

if name:

print (f"Hello, {name}!")

else:

14
print ("Hello, Guest!")

greet("Alice")

Python also supports a REPL (Read-Eval-Print Loop) mode, where you can
type Python code line by line and see immediate results. This makes it great
for quick testing and learning. Overall, Python's syntax emphasizes
readability, simplicity, and consistency, which is why it's so widely loved by
beginners and professionals alike.

Fig 5.1

5.2 Python Data Types:


In Python, data types define the kind of value a variable can hold, and they
are essential for writing correct and efficient programs. Python is a
dynamically typed language, which means you don't need to declare the data
type of a variable explicitly—Python detects it automatically at runtime. The
built-in data types in Python can be broadly categorized into several types:

15
◆ 1. Numeric Types

These include:

int – for integers (e.g., 10, -5)

float – for decimal numbers (e.g., 3.14, -0.01)

complex – for complex numbers (e.g., 2 + 3j)

◆ 2. Sequence Types

These are ordered collections:

str – string, a sequence of characters (e.g., "Hello")

list – mutable sequence of items (e.g., [1, 2, 3])

tuple – immutable sequence (e.g., (4, 5, 6))

◆ 3. Set Types

set – unordered collection of unique items (e.g., {1, 2, 3})

frozen set – like a set but immutable

◆ 4. Mapping Type

dict – a collection of key-value pairs (e.g., {"name": "Alice", "age": 25})

◆ 5. Boolean Type

bool – represents True or False, typically used in conditional expressions

◆ 6. Binary Types

Used to handle binary data:

bytes – immutable sequence of bytes

bytearray – mutable sequence of bytes

memoryview – memory-efficient view of bytes

16
◆ 7. None Type

NoneType – represents the absence of a value, written as None

Example:

a = 10 # int

b = 3.14 # float

c = "Python" # str

d = [1, 2, 3] # list

e = {"key": 1} # dict

f = True # bool

Python also allows you to check the type of a variable using the built-in type()
function, and you can convert between types using type casting, such as int(),
float(), str(), etc. Understanding data types is foundational for writing correct
Python code, as operations and functions behave differently depending on the
type of data they work with.

5.3 Operators:
In Python, operators are special symbols or keywords used to perform
operations on variables and values. Python supports several types of
operators that enable arithmetic operations, comparisons, logical decisions,
bitwise manipulations, and more. These operators make it easier to write
expressions that carry out calculations and control flow in programs.

1. Arithmetic Operators

Used to perform basic mathematical operations:

+ (Addition), - (Subtraction), * (Multiplication), / (Division)

// (Floor Division), % (Modulus), ** (Exponentiation)

Example:

a=5

b=2

print (a + b) # 7

print (a ** b) # 25

2. Comparison (Relational) Operators

17
Used to compare values and return a boolean result:

== (Equal to),!= (Not equal to)

> (Greater than), < (Less than)

>= (Greater than or equal to), <= (Less than or equal to)

Example:

x = 10

y = 20

print (x < y) # True

3. Logical Operators

Used to combine conditional statements:

and – True if both conditions are true

or – True if at least one condition is true

not – Reverses the result (True becomes False)

Example:

a=5

print (a > 2 and a < 10) # True

4. Assignment Operators

Used to assign values to variables:

=, +=, -=, *=, /=, %=, **=, //=

Example:

x=5

x += 3 # x becomes 8

5. Bitwise Operators

Used to perform operations on binary representations:

& (AND), | (OR), ^ (XOR)

~ (NOT), << (Left Shift), >> (Right Shift)

18
Example:

a=5 # 0101

b=3 # 0011

print (a & b) # 1 (0001)

6. Membership Operators

Used to test if a value is a member of a sequence (like list, string, tuple):

in – returns True if value exists

not in – returns True if value does not exist

Example:

fruits = ["apple", "banana"]

print ("apple" in fruits) # True

7. Identity Operators

Used to compare memory locations of objects:

is – returns True if two variables point to the same object

is not – returns True if they do not

Example:

x = [1, 2, 3]

y=x

print (x is y) # True

5.4 Control Statements:


Control statements in Python are used to manage the flow of execution in a
program. They allow you to make decisions, repeat actions, or jump out of
certain code blocks based on conditions. The three main types of control
statements are conditional statements, looping statements, and loop control
statements.

◆ Conditional Statements
These statements let your program make decisions based on certain
conditions. Python uses:

19
if – executes a block if the condition is true

elif – checks another condition if the previous one was false

else – executes a block if all previous conditions were false

Example:

x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

◆ Looping Statements
Loops are used to repeat a block of code multiple times.

for loop – iterates over a sequence (like a list, string, or range)

while loop – repeats as long as a condition is true

Examples:

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

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

◆ Loop Control Statements


These are used to alter the flow inside loops:

break – exits the loop immediately

continue – skips the rest of the current iteration

20
pass – does nothing, used as a placeholder

Example:

for i in range (5):


if i == 3:
break
print(i) # prints 0, 1, 2

for i in range (5):


if i == 3:
continue
print(i) # prints 0, 1, 2, 4
Control statements are the backbone of decision-making and repetition in
Python, making it possible to write intelligent, responsive, and efficient
programs.

5.4 Strings in Python:


Strings in Python

In Python, a string is a sequence of characters used to represent textual data


such as words, sentences, or even numbers written as text. Strings are
enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """) for
multi-line strings. Python strings are immutable, meaning once a string is
created, its characters cannot be changed individually—you can only create a
new string through operations. Strings support a variety of operations like
concatenation, slicing, and iteration, and are widely used in almost every
Python program.

Python offers many powerful string methods to work with text, such as:

upper () – converts to uppercase

lower () – converts to lowercase

title () – capitalizes each word

21
strip () – removes whitespace from both ends

replace (old, new) – replaces parts of the string

split () – splits the string into a list

join () – joins elements of a list into a single string

find () – returns the index of the first match

startswith () / endswith () – checks how a string begins or ends

Example:

text = “Python is awesome! “

print(text.strip().upper()) # Output: PYTHON IS AWESOME!

Strings can also be indexed and sliced:

word = "Python"

print(word[0]) # P (first character)

print(word[-1]) # n (last character)

print (word [1:4]) # yth (slicing from index 1 to 3)

Python also supports string formatting, which allows you to embed variables
into strings:

Using f-strings: f"Hello, {name}!"

Using .format(): "Hello, {}”. format(name)

Using % formatting (older style): "Hello, %s" % name

A string is a sequence of characters which is enclosed in quotes.

22
There are basically 3 types of operators supported by string:

 Basic Operators: There are two types of basic operators in string. They are
“+” and “*”.
1. Concatenation Operator (+): the concatenation operator concatenates
two strings and forms a new string.
2. Replication Operator (*): It is used to repeat a string number of times
the string will be repeated the number of times is given by the integer
value.
 Membership operators: To test whether a value is present in a sequence.
 Relational Operators: All the comparisons operators i.e., (<,>, <=,>=, == ,!=,
<>)
 Slice Notation: String Slice can be defined as substring which is the part of
string. Therefore, further substring can be obtained from a string.

Strings in Python are versatile and essential, used in everything from simple
output messages to file handling, data parsing, and user input. Their
flexibility and the wide range of methods make them one of the most
important data types in Python.

23
CHAPTER:6
Functions and Scope in Python
In Python: functions, modules, and exception handling. These concepts help
developers write organized, reusable, and error-free code, making Python a
powerful and efficient programming language for AI, data science, and
software development.

6.1 Functions in Python:


Functions in Python

In Python, a function is a reusable block of code that performs a specific task.


Functions help organize code, make it more readable, reduce repetition, and
allow for modular programming. You can define a function using the def
keyword, followed by the function name and parentheses (), which may
include parameters—placeholders for the inputs the function can receive. The
code inside the function is indented and runs only when the function is called.
If a function should return a result, you use the return statement. In

• Built-in Functions such as print (), len (), and range ().

• User-defined Functions, where programmers create their own functions


using the def

keyword.

• Function Parameters and Return Values, enabling functions to accept


input and return

output for better flexibility.

• Lambda Functions, which are small anonymous functions used for quick,
short operations.

Example:

def greet(name):

return f"Hello, {name}!"

print(greet("Alice")) # Output: Hello, Alice!

Python also supports default arguments, where parameters can have default
values:

24
python

Copy

Edit

def greet(name="Guest"):

print (f"Welcome, {name}!")

Functions can take any number of arguments using:

*args for variable-length positional arguments

**kwargs for variable-length keyword arguments

Python also allows anonymous functions using the lambda keyword. These
are short, one-line functions used for simple tasks, especially with functions
like map (), filter (), and sorted ().

Example:

square = lambda x: x * x

print (square (5)) # Output: 25

6.2 Scopes of Python


In Python, scope refers to the visibility and accessibility of variables
within different parts of a program. Scope determines where a variable
is accessible and where not. In order to understand how variables
behave within functions and how they interact with each other, it is
crucial to understand scope.

Python has two main types of scope:

Local scope:
 Variables declared within a function have local scope. They are
accessible only within the function in which they are defined.
 Local variables are created when the function is called and
destroyed when it exits.
 Local variables cannot be accessed from outside the function.

25
Global Scope:
 Variables declared outside of any function or at the top level of a
script have global scope. They are accessible throughout the
program.
 During program startup, global variables are created in memory
and remain there until the program ends.
 Global variables can be accessed from any function within the
program.

Nested scope:
 Python allows nested functions, where one function is defined
inside another.
 During nested functions, the inner function has access to
variables in the outer (enclosed) function.
 The inner function's scope is called "nested scope" because it
includes both its local scope and the enclosing function's scope.

26
CHAPTER: 7
Packages and Modules in Python
Introduction
Python is a high-level, general-purpose programming language widely used in
various domains including data science, machine learning, web development,
and automation. One of Python’s key strengths is its modular structure,
which allows developers to organize code into reusable components. This
modularity is achieved through the use of modules and packages, which play
a vital role in organizing, maintaining, and scaling Python projects effectively.

Modules in Python
A module is a file containing Python code that is written for reuse. It typically
consists of functions, classes, and variables that serve specific functionalities.
The primary goal of a module is to break down large programs into smaller,
manageable, and logically organized parts. This enhances code readability,
promotes reuse, and simplifies debugging and maintenance.

Modules form the foundational building blocks of Python programs. They can
be standard (built-in to Python), third-party (installed externally), or user-
defined (created by the developer). Using modules also allows for separation
of concerns, where each module is responsible for a specific part of the
program logic, reducing complexity in large codebases.

27
Packages in Python
A package is a hierarchical file structure that contains multiple modules
grouped together to form a collection of related functionalities. Packages allow
developers to organize their modules into directories, thereby creating a
scalable project structure. The presence of a special initialization file in the
directory indicates to Python that it should treat the directory as a package.

Packages are essential when working on large projects that involve multiple
components. By categorizing similar modules into packages, developers can
avoid naming conflicts, improve code organization, and enable better
navigation through the codebase. Packages can also contain sub-packages,
allowing for multi-level structuring of code.

Advantages of Using Modules and Packages

The use of modules and packages provides several benefits in software


development:

 Reusability: Code can be written once and reused in different


programs.

 Maintainability: Issues can be isolated and fixed within individual


modules or packages.

 Readability: Well-structured code is easier to understand and modify.

 Namespace Management: Helps avoid conflicts by isolating function


and variable names.

 Scalability: Supports growth of codebase in an organized manner,


especially in large projects.

In professional environments, especially in domains like data science,


modular programming with well-organized packages and modules is
considered a best practice.

Relevance in Data Science


In the field of data science, modular code organization is crucial due to the
multifaceted nature of tasks such as data preprocessing, analysis,
visualization, and model evaluation. Data scientists frequently work with
various Python packages designed for specific tasks. Understanding the
structure and use of modules and packages enables data scientists to build
efficient, reusable, and well-organized code pipelines.

During the course of my internship in the domain of data science, I learned


the importance of modular programming when dealing with data workflows.
The use of packages and modules made it easier to manage code, automate

28
repetitive processes, and collaborate effectively in a team environment. This
approach not only improved the quality of the code but also enhanced overall
productivity.
Modules in Python are essential components that allow programmers to
organize code into separate files and reuse functionality across different
programs. A module is simply a file containing Python code—such as
functions, classes, or variables—that can be imported and used in another
Python script. Python supports various types of modules, including built-in
modules like math, os, and datetime, which come pre-installed and provide
powerful features for mathematical operations, file handling, and date/time
manipulation. Users can also create their own custom modules, known as
user-defined modules, to structure their code better and enhance reusability.
Additionally, third-party modules like numpy, pandas, matplotlib, and flask
can be installed using Python’s package manager pip to perform specific tasks
such as data analysis, visualization, and web development. Modules can be
imported using the import statement, and specific functions or classes can be
brought in using from module import name. By using modules, Python
promotes modular programming, which leads to cleaner, more manageable
code, encourages reusability, reduces redundancy, and improves overall
program structure. Whether for small scripts or large applications, modules
play a vital role in efficient and effective Python development.

29
CHAPTER: 8
EXCEPTION HANDLING IN PYTHON
Introduction
In any programming language, errors are a natural part of the development
process. Python provides a structured way to detect and handle these errors
using a mechanism called exception handling. This allows programs to
respond to unexpected situations without crashing, thereby improving
robustness, user experience, and overall software reliability.

Exception handling is a critical concept in Python, particularly in data-driven


applications where unpredictable user input, file errors, or network issues
can arise. Effective handling of exceptions ensures smooth execution and
helps in debugging, logging, and maintaining code efficiently.

Understanding Exceptions
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions are not necessarily errors
in logic; they often result from conditions that are beyond the control of the
program, such as attempting to access a file that does not exist or dividing a
number by zero.

In Python, exceptions are objects that represent these error conditions. When
an exception occurs, Python immediately stops the current flow of the
program and looks for a way to handle the exception. If not handled, the
program terminates and displays an error message, commonly referred to as
a traceback.

Exception Handling Mechanism


Python uses a structured approach to manage exceptions through specific
keywords that help detect and respond to exceptions. The handling
mechanism allows developers to define blocks of code to try and detect errors,
and to define alternative behaviours in case an error occurs. This approach
separates normal program logic from error handling, which leads to clearer
and more maintainable code.

The exception handling structure in Python includes the following:

 A block to attempt execution.

 One or more blocks to handle specific or general exceptions.

 An optional block that executes regardless of whether an exception


occurred.

30
 An optional block for cleanup actions.

This mechanism provides flexibility and control over how different types of
exceptions are managed and ensures that the program can continue running
or exit gracefully.

Benefits of Exception Handling


Proper use of exception handling brings multiple benefits to Python programs,
especially in complex or user-facing applications. Some key advantages
include:

 Error Isolation: Helps identify exactly where the error occurred without
affecting the rest of the code.

 Improved User Experience: Allows for graceful failure and user-friendly


error messages instead of program crashes.

 Code Clarity: Separates normal program logic from error handling,


making code cleaner and easier to understand.

 System Stability: Prevents unexpected terminations by managing rare


or unanticipated situations safely.

 Maintenance & Debugging: Makes the program easier to maintain and


debug by providing detailed error messages and control flow.

Exception Hierarchy and Custom Exceptions


Python’s built-in exception classes are arranged in a hierarchy, starting from
a base class. This structure allows developers to catch a broad category of
errors or target specific ones. Additionally, Python allows developers to define
their own custom exceptions by creating new classes. This is especially useful
in larger projects, including data science applications, where domain-specific
errors need to be clearly identified and handled.

Custom exception handling improves code readability and gives a clearer


understanding of how certain errors are treated uniquely, contributing to
better error tracking and documentation.

Relevance in Data Science


In the domain of data science, exception handling is crucial due to the
unpredictability of data sources and system resources. Whether it is reading
from external files, processing real-time data, or interacting with APIs,
exceptions can occur at multiple stages. Proper handling ensures that data
pipelines do not break due to a single failure and that logs are maintained for
future analysis.

31
During my internship in the field of data science, I encountered several
scenarios where exception handling became necessary—for instance, when
handling missing values, managing file loading issues, or connecting to
external databases. Implementing structured exception handling helped me
build resilient scripts that could run reliably in different environments with
varying data inputs.

Conclusion
Exception handling is a fundamental aspect of writing robust and
professional-grade Python applications. It allows developers to anticipate and
manage errors effectively, ensuring that programs behave predictably even
under unexpected conditions. In data science and other real-world
applications, the ability to handle exceptions gracefully not only improves
performance but also enhances the reliability and trustworthiness of the
system. My internship experience underscored the importance of mastering
exception handling to create stable, scalable, and user-friendly Python
solutions.

32
CHAPTER: 9
PYTHON DATA STRCTURES
Introduction
Data structures are the foundational building blocks of any programming
language. In Python, data structures are used to store, organize, and manage
data efficiently. They provide a means of performing operations on data and
are essential for solving complex computational problems. Python offers a rich
collection of built-in data structures that are both flexible and easy to use,
which makes the language especially powerful for data science and software
development.

Understanding and utilizing Python’s data structures effectively is crucial for


writing optimized and maintainable code. They support efficient data
manipulation, enable clear program logic, and allow for better performance
across a wide range of applications.

Types of Data Structures in Python


Python provides several built-in data structures, each with unique properties,
performance characteristics, and use cases. These can be categorized into two
main types: primitive and non-primitive data structures.

1. Primitive Data Structures

These are the most basic data types in Python, including:

 Integers

 Floats

 Strings

 Booleans
While not considered data structures in the traditional sense, these primitives
form the basis for more complex types.

2. Non-Primitive Data Structures

These include more advanced structures that are capable of storing multiple
elements and performing operations on them. The primary non-primitive data
structures in Python are:

 Lists: Ordered and mutable collections of elements.

 Tuples: Ordered but immutable sequences.

 Sets: Unordered collections of unique elements.

33
 Dictionaries: Key-value pairs for efficient lookup and storage.

Each of these structures is implemented in a way that allows for dynamic


memory management, and they can grow or shrink as needed, which makes
them more flexible than traditional arrays in other languages.

Importance in Programming and Data Science


Efficient use of data structures is essential for solving real-world problems.
They help in organizing data logically and performing operations such as
insertion, deletion, traversal, and searching in a time-efficient manner.
In the context of data science, choosing the right data structure can greatly
impact the performance and scalability of data pipelines and analytical
models. For example, dictionaries are often used for mapping categorical
variables, while lists and tuples are commonly used for storing data records
or feature sets.

Python’s built-in data structures are often used in combination with third-
party libraries like pandas, which extends their functionality for handling
structured data such as tables and time series.

Key Features of Python Data Structures


 Dynamic Typing: Python data structures can hold mixed data types,
adding flexibility during implementation.

 Memory Efficiency: Python manages memory dynamically, which


simplifies development while still allowing efficient performance.

 Ease of Use: The syntax and operations associated with Python’s data
structures are intuitive and user-friendly.

 Rich Functionality: Python provides a wide range of built-in methods


for manipulating data structures, enhancing productivity and code
readability.

 Extensibility: Built-in structures can be extended or customized to


create more complex structures such as stacks, queues, and graphs
using object-oriented programming.

Applications in Real-World Projects


During the course of my internship in data science, I worked with large and
complex datasets requiring structured organization and efficient data
manipulation. Python data structures played a key role in managing this data
effectively.

34
Tasks such as data cleaning, transformation, and aggregation were greatly
facilitated by using dictionaries, lists, and sets. Understanding the underlying
structure of data allowed me to implement faster and more reliable solutions,
especially when dealing with large-scale operations or real-time data.

Data structures also supported integration with various tools and libraries,
enabling seamless development of end-to-end data workflows.

35
Chapter:10
Lists, Tuples, Sets, Dictionaries and Strings in
Python
List
A list in Python is a dynamic, ordered collection that can store elements of
different data types such as integers, floats, strings, or even other lists (nested
lists). Lists are mutable, so you can change, add, or delete elements without
creating a new list. They are defined using square brackets []. Lists are
versatile and widely used for storing a sequence of items such as a list of
student names, shopping items, or daily temperatures.

Common methods include:

 append () – adds an item to the end

 insert () – inserts an item at a specific index

 pop () – removes and returns the last element

 sort () – sorts the list in ascending order

 reverse () – reverses the list

Example:

fruits = ["apple", "banana", "cherry"]


fruits. Append("orange")

print(fruits)

Output = ['apple', 'banana', 'cherry', 'orange']

String
A string is a sequence of Unicode characters used to represent text. Strings
are immutable, meaning once created, their content cannot be changed. You
can perform various operations on strings like slicing, searching, formatting,
and joining. Strings are defined using single ' or double " quotes, and multiline
strings use triple quotes ''' or """.

Common methods include:

 upper () – converts to uppercase

 lower () – converts to lowercase

 find () – finds a substring

36
 replace () – replaces part of the string

 split () – splits the string into a list

Example:

python

message = "Python is fun"

print (message. Upper ())

Output = PYTHON IS FUN

Tuple
A tuple is a collection similar to a list but immutable, meaning once it's
created, you cannot add, remove, or change elements. Tuples are defined
using parentheses (). Because they are immutable, they can be used as
dictionary keys or elements in a set, which lists cannot do. Tuples are
usually used when the data should not be changed throughout the program,
like coordinates (x, y) or months of the year.

Common operations:

 Accessing elements via index

 Iterating with loops

 Using count () and index () methods

Example:

python

dimensions = (10, 20, 30)

print (dimensions [1])

Output = 20

Advantages:

 Faster than lists (since immutable)

 Safer for storing fixed data

Dictionary
A dictionary is an unordered, mutable collection of key-value pairs. Each
key must be unique and immutable (like strings, numbers, or tuples).
Dictionaries are written using curly braces {}. They are commonly used to
store data like student records, configurations, or any structured data.

37
Common methods:

 get () – safely gets a value by key

 keys () – returns all keys

 values () – returns all values

 items () – returns all key-value pairs

 update () – updates the dictionary with another dictionary

Example:

python

student = {"name": "Alice", "age": 20, "grade": "A"}

print(student["name"])

Output = Alice

Use Cases:

 Storing structured data (e.g., JSON-like)

 Fast lookups based on keys

 Grouping related values together

Set
A set is a collection of unordered, unique items. Sets are useful when you
want to ensure there are no duplicate entries. Sets are mutable, meaning you
can add or remove elements, but they do not support indexing or slicing
because they are unordered. Sets are ideal for operations like union,
intersection, and difference between groups.

Common methods:

 add () – adds an element

 remove () – removes an element

 union () – combines two sets

 intersection () – finds common elements

 difference () – elements in one set but not another

Example:

python

set1 = {1, 2, 3}

38
set2 = {3, 4, 5}

print (set1 & set2)

Output = {3}

39
Chapter: 11
Files and File Handling in Python
Files and File Handling in Python
In Python, file handling allows you to create, read, write, and delete files
directly from your Python program. This is especially useful when you want
to store data permanently, process text files, or interact with external files like
logs, reports, or configurations. Python provides built-in functions for file
handling, and the most common one is the open () function. This function is
used to open a file and returns a file object, which lets you perform various
operations on the file.

When opening a file, you must specify the mode:

 "r" – Read (default mode; file must exist)

 "w" – Write (creates a new file or overwrites if it exists)

 "a" – Append (adds data to the end of the file)

 "x" – Create (creates a file, returns error if file exists)

 Add "b" for binary mode (e.g., "rb" for read binary)

 Add "+" to read and write ("r+", "w+", etc.)

To read data from a file, you can use:

 read () – reads the entire file as a string

 readline () – reads one line at a time

 readlines () – reads all lines and returns a list

To write to a file, use write () or writelines (). After you're done working with a
file, it’s important to close it using close () to free up system resources.
However, the better way to handle files in Python is using a with block (also
called a context manager), which automatically closes the file when done.
Example (writing and reading a file):

python

# Writing to a file

with open ("example.txt", "w") as file:

file.write ("Hello, this is a test file.\n")

file.write("Python is fun!")

40
# Reading from a file

with open ("example.txt", "r") as file:

content = file.read()

print(content)

Advantages of Python's file handling include simplicity, cross-platform


compatibility, and powerful tools for both text and binary file operations. It is
widely used in data processing, saving logs, creating reports, and handling
user inputs.

41
Chapter: 12
Regular Expressions in Python
Regular Expressions (commonly abbreviated as RegEx) are powerful tools
used in Python to search, match, and manipulate strings based on specific
patterns. They are especially useful when you need to validate input (like
emails or phone numbers), extract specific parts of text, or perform complex
text replacements. Python provides the re module for working with regular
expressions. To use it, you must import it with import re.

At the core of regular expressions are patterns made up of special


characters. Some common ones include:

 . – matches any character except newline

 ^ – matches the start of a string

 $ – matches the end of a string

 * – matches 0 or more repetitions

 + – matches 1 or more repetitions

 ? – matches 0 or 1 repetition

 [] – matches any one character inside the brackets

 \d – matches any digit (0-9)

 \w – matches any alphanumeric character

 \s – matches any whitespace character

Common functions in the re module:


 re.match () – checks for a match only at the beginning of a string

 re.search() – searches the whole string for the first match

 re.findall() – returns all non-overlapping matches as a list

 re.sub() – replaces matched patterns with a new string

 re.compile() – compiles a regular expression pattern for reuse

Example:

python

import re

42
text = "My phone number is 9876543210"

pattern = r"\d {10}” # matches exactly 10 digits

match = re.search(pattern, text)

if match:

print ("Phone number found:", match. group ()) # Output: 9876543210

Regular expressions can be tricky at first, but they are incredibly powerful
once mastered. You can build anything from simple string filters to complex
parsers. Python also allows the use of flags like re.IGNORECASE or
re.MULTILINE to control how matching is done.

43
ACCEPTANCE LETTER FROM SKILLDZIRE
ORGANIZATION

iv
CERTIFICATE FROM INTERN ORGANIZATION

v
DECLARATION

I hereby declare that the work presented in this report titled


"PYTHON COURSE Internship Report" is the result of my own
research and study during the internship period at
SKILLDZIRE, undertaken from 16-DEC-2024 to 12-APR-2025.
This report is being submitted in partial fulfilment of the
requirements for the completion of my B.TECH, VISAKHA
INSTITUTE OF ENGINEERING AND
TECHNOLOGY
AFFLIATED TO JNTUGV. All the information, data and results
included in this report are genuine and have been collected,
analyzed, and interpreted by me. Any references or
contributions made by other authors or researchers have
been duly acknowledged in the form of citations and
references. I also confirm that this report has not been
submitted elsewhere for the award of any degree, diploma, or
certificate.

Place: Visakhapatnam Y. ANAND

Date: (21NT1A0458)

vi
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have
supported and guided me throughout my Python Course internship. My
heartfelt thanks to Skill Dzire Organization for providing me with the
opportunity to work and enhance my skills in the field of Python course. I am
deeply thankful to Visakha Institute of Engineering & Technology (VIET)
for offering a supportive environment that made this experience possible. I
extend my sincere appreciation to Dr. G. Satyanarayana, Chairman of VIET,
for his visionary leadership, and Dr. G.V. Pradeep Varma, Principal of VIET,
for his continuous encouragement. I would also like to thank Dr. D. Santha
Rao, Dean of Academics, for his insightful guidance, and Dr. P. Varma,
Training and Placement Officer (TPO), for his efforts in facilitating this
internship. My thanks are also due to Dr. B. Jeevana Rao, Head of the
Department of Electronics and Communication Engineering (ECE), for his
academic support. I am especially grateful to my Project Guide, Mrs. K.
KANTHI KINNERA M. tech, (Ph . D), for her valuable mentorship, constant
encouragement, and expert guidance throughout the internship. Additionally,
I would like to acknowledge the faculty members of the ECE department
whose teachings and support have played a crucial role in my academic
development.

vii
ABSTRACT
Data science encompasses a set of principles, problem definitions, algorithms,
and processes for extracting nonobvious and useful patterns from large data
sets. Many of the elements of data science have been developed in related
fields such as machine learning and data mining. In fact, the terms data
science, machine learning, and data mining are often used interchangeably.
The commonality across these disciplines is a focus on improving decision
making through the analysis of data. However, although data science borrows
from these other fields, it is broader in scope. Machine learning (ML) focuses
on the design and evaluation of algorithms for extracting patterns from data.
Data mining generally deals with the analysis of structured data and often
implies an emphasis on commercial applications. Data science takes all of
these considerations into account but also takes up other challenges, such as
the capturing, cleaning, and transforming of unstructured social media and
web data; the use of big-data technologies to store and process big,
unstructured data sets; and questions related to data ethics and regulation.

viii
CONTENTS
S.NO Name of the Topic/Chapter Page No. From
To

1 Introduction to Artificial Intelligence 1-4


What is AI 1
How AI Works 1
Types of AI 2
Training models of AI 3
Benefits of AI 4
Applications of AI 4
2 Introduction to Data Science 5-8
What is Data Science 5
Where Data Science Needed 5
What is Data, Types of Data 6
How Does a Data Scientist Work 8
Applications Of Data science 8
3 Machine Learning Concepts and Applications 9-10
Why do we need Machine Learning 9
What Makes a Machine learn 9
Benefits of Machine Learning 10
Challenges of Machine Learning 10
4 Introduction to Python for AI & Data Science 11-12
Why python for data science 11
Python Important Features & Interfaces 11
Advantages and disadvantages of python 12
Difference between Python and R Language 12
5 Python Basics and Syntax, Operators & Control 13-23
Statements
Syntax of Python 14
Data Types & Special Characters 15

ix
Operators 17
Strings in Python 19
6 Functions and Scope in Python 24-26
Functions of Python 24
Scopes of python 25
7 Packages & Modules in Python 27-29
8 Exception Handling in Python 30-32
9 Python Data Structures Overview 33-35
10 Lists, Strings, Sets, Tuples, and Dictionaries in 36-39
Python
11 Files and File Handling in Python 40-41
12 Regular Expressions in Python 42-43
13 CONCLUSION 44

x
CHAPTER 1
INTRODUCTION TO AI

Fig1.0

1.1 What is ARTIFICIAL INTELLIGENCE:


Artificial intelligence (AI) is a set of technologies that enable computers to
perform a variety of advanced functions, including the ability to see,
understand and translate spoken and written language, analyse data,
make recommendations, and more.

AI is the backbone of innovation in modern computing, unlocking value


for individuals and businesses. For example, optical character
recognition (OCR) uses AI to extract text and data from images and
documents, turns unstructured content into business-ready structured
data, and unlocks valuable insights. Artificial intelligence is a field of
science concerned with building computers and machines that can
reason, learn, and act in such a way that would normally require human
intelligence or that involves data whose scale exceeds what humans can
analyse.

1.2 HOW AI WORKS:

Fig1.1

1
1.3 Types of Artificial Intelligence:
Artificial intelligence can be organized in several ways, depending on
stages of development or actions being performed.

For instance, four stages of AI development are commonly recognized.

Reactive machines: Limited AI that only reacts to different kinds of


stimuli based on preprogrammed rules. Does not use memory and thus
cannot learn with new data. IBM’s Deep Blue that beat chess champion
Garry Kasparov in 1997 was an example of a reactive machine.

Limited memory: Most modern AI is considered to be limited memory.


It can use memory to improve over time by being trained with new data,
typically through an artificial neural network or other training model.
Deep learning, a subset of machine learning, is considered limited
memory artificial intelligence time

Theory of mind: Theory of mind AI does not currently exist, but


research is ongoing into its possibilities. It describes AI that can
emulate the human mind and has decision-making capabilities equal
to that of a human, including recognizing and remembering emotions
and reacting in social situations as a human would.

Self-aware: A step above theory of mind AI, self-aware AI describes a


mythical machine that is aware of its own existence and has the
intellectual and emotional capabilities of a human. Like theory of mind
AI, self-aware AI does not currently exist.

Fig 1.2

2
1.4 Artificial Intelligence Training Models:
Supervised learning is a machine learning model that maps a specific
input to an output using labelled training data (structured data).

Unsupervised learning is a machine learning model that learns


patterns based on unlabelled data (unstructured data). Unlike
supervised learning, the end result is not known ahead of time. Rather,
the algorithm learns from the data, categorizing it into groups based on
attributes. For instance, unsupervised learning is good at pattern
matching and descriptive modelling.

In addition to supervised and unsupervised learning, a mixed approach


called semi-supervised learning is often employed, where only some of
the data is labelled. In semi-supervised learning, an end result is
known, but the algorithm must figure out how to organize and structure
the data to achieve the desired results.

Fig 1.3

3
1.5 Benefits of AI:

Fig 1.4
1.6 Applications of AI:

Fig 1.5

4
CHAPTER : 2
What is Data Science
Data Science is a combination of multiple disciplines that uses statistics,
data analysis, and machine learning to analyse data and to extract
knowledge and insights from it.

Data Science is about data gathering, analysis and decision-


making.

Data Science is about finding patterns in data, through analysis, and make
future predictions.

 By using Data Science, companies are able to make:


 Better decisions (should we choose A or B)
 Predictive analysis (what will happen next?)
 Pattern discoveries (find pattern, or maybe hidden information in the
data)

2.1 Where is Data Science Needed:


 For route planning: To discover the best routes to ship
 To foresee delays for flight/ship/train etc. (through predictive
analysis)
 To create promotional offers
 To find the best suited time to deliver goods
 To forecast the next years revenue for a company
 To analyse health benefit of training
 To predict who will win elections

Data Science can be applied in nearly every part of a business where data is
available. Examples are:

 Consumer goods
 Stock markets
 Industry
 Politics
 Logistic companies
 E-commerce

2.2 What is Data:


Data is a collection of information.

5
One purpose of Data Science is to structure data, making it
interpretable and easy to work with.

Data can be categorized into two groups:

 Structured data
 Unstructured data

Fig 2.1
2.3 How Does a Data Scientist Work:
A Data Scientist requires expertise in several backgrounds:

 Machine Learning
 Statistics
 Programming (Python or R)
 Mathematics
 Databases

6
Fig 2.2
1. Problem Statement:

No work starts without motivation, Data science is no exception though.


It’s really important to declare or formulate your problem statement
very clearly and precisely. Your whole model and it’s working depend
on your statement. Many scientists consider this as the main and much
important step of Date Science. So, make sure what’s your problem
statement and how well can it add value to business or any other
organization.

2. Data Collection:

After defining the problem statement, the next obvious step is to go in


search of data that you might require for your model. You must do good
research, find all that you need. Data can be in any form i.e.
unstructured or structured. It might be in various forms like videos,
spreadsheets, coded forms, etc. You must collect all these kinds of
sources.

3. Data Cleaning:

As you have formulated your motive and also you did collect your data,
the next step to do is cleaning. Yes, it is! Data cleaning is the most
favourite thing for data scientists to do. Data cleaning is all about the
removal of missing, redundant, unnecessary and duplicate data from
your collection. There are various tools to do so with the help of
programming in either R or Python. It’s totally on you to choose one of
them. Various scientist has their opinion on which to choose. When it
comes to the statistical part, R is preferred over Python, as it has the
privilege of more than 12,000 packages. While python is used as it is
fast, easily accessible and we can perform the same things as we can in
R with the help of various packages.

4. Data Analysis and Exploration:

7
It’s one of the prime things in data science to do and time to get inner
Holmes out. It’s about analysing the structure of data, finding hidden
patterns in them, studying behaviours, visualizing the effects of one
variable over others and then concluding. We can explore the data with
the help of various graphs formed with the help of libraries using any
programming language. In R, GGplot is one of the most famous models
while Matplotlib in Python.

5. Data Modelling:

Once you are done with your study that you have formed from data
visualization, you must start building a hypothesis model such that it
may yield you a good prediction in future. Here, you must choose a good
algorithm that best fit to your model. There different kinds of algorithms
from regression to classification, SVM (Support vector machines),
Clustering, etc. Your model can be of a Machine Learning algorithm.
You train your model with the train data and then test it with test data.
There are various methods to do so. One of them is the K-fold method
where you split your whole data into two parts, one is Train and the
other is test data. On these bases, you train your model.

6. Optimization and Deployment:

You followed each and every step and hence build a model that you feel
is the best fit. But how can you decide how well your model is
performing? This where optimization comes. You test your data and find
how well it is performing by checking its accuracy. In short, you check
the efficiency of the data model and thus try to optimize it for better
accurate prediction. Deployment deals with the launch of your model
and let the people outside there to benefit from that. You can also obtain
feedback from organizations and people to know their need and then to
work more on your model.

2.4 Applications of Data Science:

Fig 2.3

8
CHAPTER : 3
Machine Learning concepts and Applications
Machine learning (ML) allows computers to learn and make decisions without
being explicitly programmed. It involves feeding data into algorithms to
identify patterns and make predictions on new data. Machine learning is used
in various applications, including image and speech recognition, natural
language processing, and recommender systems.

3.1 Why do we need Machine Learning?


Machine Learning algorithm learns from data, trains on patterns, and
solves or predicts complex problems beyond the scope of traditional
programming. It drives better decision-making and tackles intricate
challenges efficiently.

 Solving Complex Business Problems


 Handling Large Volumes of Data
 Automate Repetitive Tasks
 Personalized User Experience
 Self-Improvement in Performance

3.2 What Makes a Machine “Learn”?


A machine “learns” by recognizing patterns and improving its
performance on a task based on data, without being explicitly
programmed.

The process involves:

Data Input: Machines require data (e.g., text, images, numbers) to


analyse.
Algorithms: Algorithms process the data, finding patterns or
relationships.

Model Training: Machines learn by adjusting their parameters based


on the input data using mathematical models.

Feedback Loop: The machine compares predictions to actual outcomes


and corrects errors (via optimization methods like gradient descent).

Experience and Iteration: Repeating this process with more data


improves the machine’s accuracy over time.

Evaluation and Generalization: The model is tested on unseen data


to ensure it performs well on real-world tasks.

9
3.3 Importance of Data in Machine Learning:
Data is the foundation of machine learning (ML). Without quality data,
ML models cannot learn, perform, or make accurate predictions.

 Data provides the examples from which models learn patterns


and relationships.
 High-quality and diverse data improves model accuracy and
generalization.
 Data ensures models understand real-world scenarios and adapt
to practical applications.
 Features derived from data are critical for training models.
 Separate datasets for validation and testing assess how well the
model performs on unseen data.
 Data fuels iterative improvements in ML models through
feedback loops.

Fig 3.0

3.5 Challenges of Machine Learning:

Fig 3.1

10
CHAPTER : 4
PYTHON
Python is a programming language widely used by Data Scientists.

Python has in-built mathematical libraries and functions, making it easier to


calculate mathematical problems and to perform data analysis.

4.1 Why Python for Data Science?


Python is favoured in data science due to its readability, simplicity, and
versatility. Its extensive libraries and frameworks streamline complex
tasks, allowing data scientists to focus on problem-solving rather than
coding intricacies.

Fig 4.1

4.2 Features of Python:

Fig 4.2

11
4.3 Key Libraries and Tools:
NumPy: A fundamental library for numerical operations in Python,
supporting large, multi-dimensional arrays and matrices.

pandas: A powerful library for data manipulation and analysis, offering


data structures like Data Frames to handle structured data efficiently.

Scikit-learn: A comprehensive library for machine learning, providing


simple and efficient data mining and analysis tools.

Matplotlib and Seaborn: Libraries for creating static, animated, and


interactive visualizations, helping to understand data patterns and
trends

Fig 4.3

4.4 Advantages and Disadvantages of Python:

Fig 4.4

12
4.5 Applications of Python:

Fig 4.5

Benefits of Python:

Fig 4.6

4.6 Difference between Python and R Language

Fig 4.7

13
CHAPTER: 5
Python Syntax, Data Types & Operators
Python is known for its clean and readable syntax, which makes it an
excellent language for beginners and professionals working in AI, data
science, and software development.

5.1 Python Syntax


Python syntax refers to the set of rules that define how a Python program is
written and interpreted. One of the most distinctive and beginner-friendly
aspects of Python is its clean and readable syntax. Unlike many other
programming languages that use curly braces {} to define code blocks, Python
uses indentation (whitespace). This means that consistent indentation is not
just a style, but a requirement in Python—usually 4 spaces are used per
indentation level.

A Python program is made up of statements and expressions. Statements are


instructions (like if, for, or def) that perform actions, while expressions are
combinations of values and operators that evaluate to a result. Python is case-
sensitive, so Name, name, and NAME are all treated as different identifiers.

Some key points of Python syntax:

Comments start with # and are ignored by the interpreter. Use them to explain
your code.
Variables do not require a type declaration; the type is inferred from the value
(e.g., x = 10).

Functions are defined using the def keyword, and blocks of code are
structured using colons (:) followed by indented lines.

Control structures like if, elif, else, for, and while are written in a natural,
readable way.

Importing modules is done using the import keyword.

Example:

# This is a comment

def greet(name):

if name:

print (f"Hello, {name}!")

else:

14
print ("Hello, Guest!")

greet("Alice")

Python also supports a REPL (Read-Eval-Print Loop) mode, where you can
type Python code line by line and see immediate results. This makes it great
for quick testing and learning. Overall, Python's syntax emphasizes
readability, simplicity, and consistency, which is why it's so widely loved by
beginners and professionals alike.

Fig 5.1

5.2 Python Data Types:


In Python, data types define the kind of value a variable can hold, and they
are essential for writing correct and efficient programs. Python is a
dynamically typed language, which means you don't need to declare the data
type of a variable explicitly—Python detects it automatically at runtime. The
built-in data types in Python can be broadly categorized into several types:

15
◆ 1. Numeric Types

These include:

int – for integers (e.g., 10, -5)

float – for decimal numbers (e.g., 3.14, -0.01)

complex – for complex numbers (e.g., 2 + 3j)

◆ 2. Sequence Types

These are ordered collections:

str – string, a sequence of characters (e.g., "Hello")

list – mutable sequence of items (e.g., [1, 2, 3])

tuple – immutable sequence (e.g., (4, 5, 6))

◆ 3. Set Types

set – unordered collection of unique items (e.g., {1, 2, 3})

frozen set – like a set but immutable

◆ 4. Mapping Type

dict – a collection of key-value pairs (e.g., {"name": "Alice", "age": 25})

◆ 5. Boolean Type

bool – represents True or False, typically used in conditional expressions

◆ 6. Binary Types

Used to handle binary data:

bytes – immutable sequence of bytes

bytearray – mutable sequence of bytes

memoryview – memory-efficient view of bytes

16
◆ 7. None Type

NoneType – represents the absence of a value, written as None

Example:

a = 10 # int

b = 3.14 # float

c = "Python" # str

d = [1, 2, 3] # list

e = {"key": 1} # dict

f = True # bool

Python also allows you to check the type of a variable using the built-in type()
function, and you can convert between types using type casting, such as int(),
float(), str(), etc. Understanding data types is foundational for writing correct
Python code, as operations and functions behave differently depending on the
type of data they work with.

5.3 Operators:
In Python, operators are special symbols or keywords used to perform
operations on variables and values. Python supports several types of
operators that enable arithmetic operations, comparisons, logical decisions,
bitwise manipulations, and more. These operators make it easier to write
expressions that carry out calculations and control flow in programs.

1. Arithmetic Operators

Used to perform basic mathematical operations:

+ (Addition), - (Subtraction), * (Multiplication), / (Division)

// (Floor Division), % (Modulus), ** (Exponentiation)

Example:

a=5

b=2

print (a + b) # 7

print (a ** b) # 25

2. Comparison (Relational) Operators

17
Used to compare values and return a boolean result:

== (Equal to),!= (Not equal to)

> (Greater than), < (Less than)

>= (Greater than or equal to), <= (Less than or equal to)

Example:

x = 10

y = 20

print (x < y) # True

3. Logical Operators

Used to combine conditional statements:

and – True if both conditions are true

or – True if at least one condition is true

not – Reverses the result (True becomes False)

Example:

a=5

print (a > 2 and a < 10) # True

4. Assignment Operators

Used to assign values to variables:

=, +=, -=, *=, /=, %=, **=, //=

Example:

x=5

x += 3 # x becomes 8

5. Bitwise Operators

Used to perform operations on binary representations:

& (AND), | (OR), ^ (XOR)

~ (NOT), << (Left Shift), >> (Right Shift)

18
Example:

a=5 # 0101

b=3 # 0011

print (a & b) # 1 (0001)

6. Membership Operators

Used to test if a value is a member of a sequence (like list, string, tuple):

in – returns True if value exists

not in – returns True if value does not exist

Example:

fruits = ["apple", "banana"]

print ("apple" in fruits) # True

7. Identity Operators

Used to compare memory locations of objects:

is – returns True if two variables point to the same object

is not – returns True if they do not

Example:

x = [1, 2, 3]

y=x

print (x is y) # True

5.4 Control Statements:


Control statements in Python are used to manage the flow of execution in a
program. They allow you to make decisions, repeat actions, or jump out of
certain code blocks based on conditions. The three main types of control
statements are conditional statements, looping statements, and loop control
statements.

◆ Conditional Statements
These statements let your program make decisions based on certain
conditions. Python uses:

19
if – executes a block if the condition is true

elif – checks another condition if the previous one was false

else – executes a block if all previous conditions were false

Example:

x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

◆ Looping Statements
Loops are used to repeat a block of code multiple times.

for loop – iterates over a sequence (like a list, string, or range)

while loop – repeats as long as a condition is true

Examples:

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

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

◆ Loop Control Statements


These are used to alter the flow inside loops:

break – exits the loop immediately

continue – skips the rest of the current iteration

20
pass – does nothing, used as a placeholder

Example:

for i in range (5):


if i == 3:
break
print(i) # prints 0, 1, 2

for i in range (5):


if i == 3:
continue
print(i) # prints 0, 1, 2, 4
Control statements are the backbone of decision-making and repetition in
Python, making it possible to write intelligent, responsive, and efficient
programs.

5.4 Strings in Python:


Strings in Python

In Python, a string is a sequence of characters used to represent textual data


such as words, sentences, or even numbers written as text. Strings are
enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """) for
multi-line strings. Python strings are immutable, meaning once a string is
created, its characters cannot be changed individually—you can only create a
new string through operations. Strings support a variety of operations like
concatenation, slicing, and iteration, and are widely used in almost every
Python program.

Python offers many powerful string methods to work with text, such as:

upper () – converts to uppercase

lower () – converts to lowercase

title () – capitalizes each word

21
strip () – removes whitespace from both ends

replace (old, new) – replaces parts of the string

split () – splits the string into a list

join () – joins elements of a list into a single string

find () – returns the index of the first match

startswith () / endswith () – checks how a string begins or ends

Example:

text = “Python is awesome! “

print(text.strip().upper()) # Output: PYTHON IS AWESOME!

Strings can also be indexed and sliced:

word = "Python"

print(word[0]) # P (first character)

print(word[-1]) # n (last character)

print (word [1:4]) # yth (slicing from index 1 to 3)

Python also supports string formatting, which allows you to embed variables
into strings:

Using f-strings: f"Hello, {name}!"

Using .format(): "Hello, {}”. format(name)

Using % formatting (older style): "Hello, %s" % name

A string is a sequence of characters which is enclosed in quotes.

22
There are basically 3 types of operators supported by string:

 Basic Operators: There are two types of basic operators in string. They are
“+” and “*”.
1. Concatenation Operator (+): the concatenation operator concatenates
two strings and forms a new string.
2. Replication Operator (*): It is used to repeat a string number of times
the string will be repeated the number of times is given by the integer
value.
 Membership operators: To test whether a value is present in a sequence.
 Relational Operators: All the comparisons operators i.e., (<,>, <=,>=, == ,!=,
<>)
 Slice Notation: String Slice can be defined as substring which is the part of
string. Therefore, further substring can be obtained from a string.

Strings in Python are versatile and essential, used in everything from simple
output messages to file handling, data parsing, and user input. Their
flexibility and the wide range of methods make them one of the most
important data types in Python.

23
CHAPTER:6
Functions and Scope in Python
In Python: functions, modules, and exception handling. These concepts help
developers write organized, reusable, and error-free code, making Python a
powerful and efficient programming language for AI, data science, and
software development.

6.1 Functions in Python:


Functions in Python

In Python, a function is a reusable block of code that performs a specific task.


Functions help organize code, make it more readable, reduce repetition, and
allow for modular programming. You can define a function using the def
keyword, followed by the function name and parentheses (), which may
include parameters—placeholders for the inputs the function can receive. The
code inside the function is indented and runs only when the function is called.
If a function should return a result, you use the return statement. In

• Built-in Functions such as print (), len (), and range ().

• User-defined Functions, where programmers create their own functions


using the def

keyword.

• Function Parameters and Return Values, enabling functions to accept


input and return

output for better flexibility.

• Lambda Functions, which are small anonymous functions used for quick,
short operations.

Example:

def greet(name):

return f"Hello, {name}!"

print(greet("Alice")) # Output: Hello, Alice!

Python also supports default arguments, where parameters can have default
values:

24
python

Copy

Edit

def greet(name="Guest"):

print (f"Welcome, {name}!")

Functions can take any number of arguments using:

*args for variable-length positional arguments

**kwargs for variable-length keyword arguments

Python also allows anonymous functions using the lambda keyword. These
are short, one-line functions used for simple tasks, especially with functions
like map (), filter (), and sorted ().

Example:

square = lambda x: x * x

print (square (5)) # Output: 25

6.2 Scopes of Python


In Python, scope refers to the visibility and accessibility of variables
within different parts of a program. Scope determines where a variable
is accessible and where not. In order to understand how variables
behave within functions and how they interact with each other, it is
crucial to understand scope.

Python has two main types of scope:

Local scope:
 Variables declared within a function have local scope. They are
accessible only within the function in which they are defined.
 Local variables are created when the function is called and
destroyed when it exits.
 Local variables cannot be accessed from outside the function.

25
Global Scope:
 Variables declared outside of any function or at the top level of a
script have global scope. They are accessible throughout the
program.
 During program startup, global variables are created in memory
and remain there until the program ends.
 Global variables can be accessed from any function within the
program.

Nested scope:
 Python allows nested functions, where one function is defined
inside another.
 During nested functions, the inner function has access to
variables in the outer (enclosed) function.
 The inner function's scope is called "nested scope" because it
includes both its local scope and the enclosing function's scope.

26
CHAPTER: 7
Packages and Modules in Python
Introduction
Python is a high-level, general-purpose programming language widely used in
various domains including data science, machine learning, web development,
and automation. One of Python’s key strengths is its modular structure,
which allows developers to organize code into reusable components. This
modularity is achieved through the use of modules and packages, which play
a vital role in organizing, maintaining, and scaling Python projects effectively.

Modules in Python
A module is a file containing Python code that is written for reuse. It typically
consists of functions, classes, and variables that serve specific functionalities.
The primary goal of a module is to break down large programs into smaller,
manageable, and logically organized parts. This enhances code readability,
promotes reuse, and simplifies debugging and maintenance.

Modules form the foundational building blocks of Python programs. They can
be standard (built-in to Python), third-party (installed externally), or user-
defined (created by the developer). Using modules also allows for separation
of concerns, where each module is responsible for a specific part of the
program logic, reducing complexity in large codebases.

27
Packages in Python
A package is a hierarchical file structure that contains multiple modules
grouped together to form a collection of related functionalities. Packages allow
developers to organize their modules into directories, thereby creating a
scalable project structure. The presence of a special initialization file in the
directory indicates to Python that it should treat the directory as a package.

Packages are essential when working on large projects that involve multiple
components. By categorizing similar modules into packages, developers can
avoid naming conflicts, improve code organization, and enable better
navigation through the codebase. Packages can also contain sub-packages,
allowing for multi-level structuring of code.

Advantages of Using Modules and Packages

The use of modules and packages provides several benefits in software


development:

 Reusability: Code can be written once and reused in different


programs.

 Maintainability: Issues can be isolated and fixed within individual


modules or packages.

 Readability: Well-structured code is easier to understand and modify.

 Namespace Management: Helps avoid conflicts by isolating function


and variable names.

 Scalability: Supports growth of codebase in an organized manner,


especially in large projects.

In professional environments, especially in domains like data science,


modular programming with well-organized packages and modules is
considered a best practice.

Relevance in Data Science


In the field of data science, modular code organization is crucial due to the
multifaceted nature of tasks such as data preprocessing, analysis,
visualization, and model evaluation. Data scientists frequently work with
various Python packages designed for specific tasks. Understanding the
structure and use of modules and packages enables data scientists to build
efficient, reusable, and well-organized code pipelines.

During the course of my internship in the domain of data science, I learned


the importance of modular programming when dealing with data workflows.
The use of packages and modules made it easier to manage code, automate

28
repetitive processes, and collaborate effectively in a team environment. This
approach not only improved the quality of the code but also enhanced overall
productivity.
Modules in Python are essential components that allow programmers to
organize code into separate files and reuse functionality across different
programs. A module is simply a file containing Python code—such as
functions, classes, or variables—that can be imported and used in another
Python script. Python supports various types of modules, including built-in
modules like math, os, and datetime, which come pre-installed and provide
powerful features for mathematical operations, file handling, and date/time
manipulation. Users can also create their own custom modules, known as
user-defined modules, to structure their code better and enhance reusability.
Additionally, third-party modules like numpy, pandas, matplotlib, and flask
can be installed using Python’s package manager pip to perform specific tasks
such as data analysis, visualization, and web development. Modules can be
imported using the import statement, and specific functions or classes can be
brought in using from module import name. By using modules, Python
promotes modular programming, which leads to cleaner, more manageable
code, encourages reusability, reduces redundancy, and improves overall
program structure. Whether for small scripts or large applications, modules
play a vital role in efficient and effective Python development.

29
CHAPTER: 8
EXCEPTION HANDLING IN PYTHON
Introduction
In any programming language, errors are a natural part of the development
process. Python provides a structured way to detect and handle these errors
using a mechanism called exception handling. This allows programs to
respond to unexpected situations without crashing, thereby improving
robustness, user experience, and overall software reliability.

Exception handling is a critical concept in Python, particularly in data-driven


applications where unpredictable user input, file errors, or network issues
can arise. Effective handling of exceptions ensures smooth execution and
helps in debugging, logging, and maintaining code efficiently.

Understanding Exceptions
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions are not necessarily errors
in logic; they often result from conditions that are beyond the control of the
program, such as attempting to access a file that does not exist or dividing a
number by zero.

In Python, exceptions are objects that represent these error conditions. When
an exception occurs, Python immediately stops the current flow of the
program and looks for a way to handle the exception. If not handled, the
program terminates and displays an error message, commonly referred to as
a traceback.

Exception Handling Mechanism


Python uses a structured approach to manage exceptions through specific
keywords that help detect and respond to exceptions. The handling
mechanism allows developers to define blocks of code to try and detect errors,
and to define alternative behaviours in case an error occurs. This approach
separates normal program logic from error handling, which leads to clearer
and more maintainable code.

The exception handling structure in Python includes the following:

 A block to attempt execution.

 One or more blocks to handle specific or general exceptions.

 An optional block that executes regardless of whether an exception


occurred.

30
 An optional block for cleanup actions.

This mechanism provides flexibility and control over how different types of
exceptions are managed and ensures that the program can continue running
or exit gracefully.

Benefits of Exception Handling


Proper use of exception handling brings multiple benefits to Python programs,
especially in complex or user-facing applications. Some key advantages
include:

 Error Isolation: Helps identify exactly where the error occurred without
affecting the rest of the code.

 Improved User Experience: Allows for graceful failure and user-friendly


error messages instead of program crashes.

 Code Clarity: Separates normal program logic from error handling,


making code cleaner and easier to understand.

 System Stability: Prevents unexpected terminations by managing rare


or unanticipated situations safely.

 Maintenance & Debugging: Makes the program easier to maintain and


debug by providing detailed error messages and control flow.

Exception Hierarchy and Custom Exceptions


Python’s built-in exception classes are arranged in a hierarchy, starting from
a base class. This structure allows developers to catch a broad category of
errors or target specific ones. Additionally, Python allows developers to define
their own custom exceptions by creating new classes. This is especially useful
in larger projects, including data science applications, where domain-specific
errors need to be clearly identified and handled.

Custom exception handling improves code readability and gives a clearer


understanding of how certain errors are treated uniquely, contributing to
better error tracking and documentation.

Relevance in Data Science


In the domain of data science, exception handling is crucial due to the
unpredictability of data sources and system resources. Whether it is reading
from external files, processing real-time data, or interacting with APIs,
exceptions can occur at multiple stages. Proper handling ensures that data
pipelines do not break due to a single failure and that logs are maintained for
future analysis.

31
During my internship in the field of data science, I encountered several
scenarios where exception handling became necessary—for instance, when
handling missing values, managing file loading issues, or connecting to
external databases. Implementing structured exception handling helped me
build resilient scripts that could run reliably in different environments with
varying data inputs.

Conclusion
Exception handling is a fundamental aspect of writing robust and
professional-grade Python applications. It allows developers to anticipate and
manage errors effectively, ensuring that programs behave predictably even
under unexpected conditions. In data science and other real-world
applications, the ability to handle exceptions gracefully not only improves
performance but also enhances the reliability and trustworthiness of the
system. My internship experience underscored the importance of mastering
exception handling to create stable, scalable, and user-friendly Python
solutions.

32
CHAPTER: 9
PYTHON DATA STRCTURES
Introduction
Data structures are the foundational building blocks of any programming
language. In Python, data structures are used to store, organize, and manage
data efficiently. They provide a means of performing operations on data and
are essential for solving complex computational problems. Python offers a rich
collection of built-in data structures that are both flexible and easy to use,
which makes the language especially powerful for data science and software
development.

Understanding and utilizing Python’s data structures effectively is crucial for


writing optimized and maintainable code. They support efficient data
manipulation, enable clear program logic, and allow for better performance
across a wide range of applications.

Types of Data Structures in Python


Python provides several built-in data structures, each with unique properties,
performance characteristics, and use cases. These can be categorized into two
main types: primitive and non-primitive data structures.

1. Primitive Data Structures

These are the most basic data types in Python, including:

 Integers

 Floats

 Strings

 Booleans
While not considered data structures in the traditional sense, these primitives
form the basis for more complex types.

2. Non-Primitive Data Structures

These include more advanced structures that are capable of storing multiple
elements and performing operations on them. The primary non-primitive data
structures in Python are:

 Lists: Ordered and mutable collections of elements.

 Tuples: Ordered but immutable sequences.

 Sets: Unordered collections of unique elements.

33
 Dictionaries: Key-value pairs for efficient lookup and storage.

Each of these structures is implemented in a way that allows for dynamic


memory management, and they can grow or shrink as needed, which makes
them more flexible than traditional arrays in other languages.

Importance in Programming and Data Science


Efficient use of data structures is essential for solving real-world problems.
They help in organizing data logically and performing operations such as
insertion, deletion, traversal, and searching in a time-efficient manner.
In the context of data science, choosing the right data structure can greatly
impact the performance and scalability of data pipelines and analytical
models. For example, dictionaries are often used for mapping categorical
variables, while lists and tuples are commonly used for storing data records
or feature sets.

Python’s built-in data structures are often used in combination with third-
party libraries like pandas, which extends their functionality for handling
structured data such as tables and time series.

Key Features of Python Data Structures


 Dynamic Typing: Python data structures can hold mixed data types,
adding flexibility during implementation.

 Memory Efficiency: Python manages memory dynamically, which


simplifies development while still allowing efficient performance.

 Ease of Use: The syntax and operations associated with Python’s data
structures are intuitive and user-friendly.

 Rich Functionality: Python provides a wide range of built-in methods


for manipulating data structures, enhancing productivity and code
readability.

 Extensibility: Built-in structures can be extended or customized to


create more complex structures such as stacks, queues, and graphs
using object-oriented programming.

Applications in Real-World Projects


During the course of my internship in data science, I worked with large and
complex datasets requiring structured organization and efficient data
manipulation. Python data structures played a key role in managing this data
effectively.

34
Tasks such as data cleaning, transformation, and aggregation were greatly
facilitated by using dictionaries, lists, and sets. Understanding the underlying
structure of data allowed me to implement faster and more reliable solutions,
especially when dealing with large-scale operations or real-time data.

Data structures also supported integration with various tools and libraries,
enabling seamless development of end-to-end data workflows.

35
Chapter:10
Lists, Tuples, Sets, Dictionaries and Strings in
Python
List
A list in Python is a dynamic, ordered collection that can store elements of
different data types such as integers, floats, strings, or even other lists (nested
lists). Lists are mutable, so you can change, add, or delete elements without
creating a new list. They are defined using square brackets []. Lists are
versatile and widely used for storing a sequence of items such as a list of
student names, shopping items, or daily temperatures.

Common methods include:

 append () – adds an item to the end

 insert () – inserts an item at a specific index

 pop () – removes and returns the last element

 sort () – sorts the list in ascending order

 reverse () – reverses the list

Example:

fruits = ["apple", "banana", "cherry"]


fruits. Append("orange")

print(fruits)

Output = ['apple', 'banana', 'cherry', 'orange']

String
A string is a sequence of Unicode characters used to represent text. Strings
are immutable, meaning once created, their content cannot be changed. You
can perform various operations on strings like slicing, searching, formatting,
and joining. Strings are defined using single ' or double " quotes, and multiline
strings use triple quotes ''' or """.

Common methods include:

 upper () – converts to uppercase

 lower () – converts to lowercase

 find () – finds a substring

36
 replace () – replaces part of the string

 split () – splits the string into a list

Example:

python

message = "Python is fun"

print (message. Upper ())

Output = PYTHON IS FUN

Tuple
A tuple is a collection similar to a list but immutable, meaning once it's
created, you cannot add, remove, or change elements. Tuples are defined
using parentheses (). Because they are immutable, they can be used as
dictionary keys or elements in a set, which lists cannot do. Tuples are
usually used when the data should not be changed throughout the program,
like coordinates (x, y) or months of the year.

Common operations:

 Accessing elements via index

 Iterating with loops

 Using count () and index () methods

Example:

python

dimensions = (10, 20, 30)

print (dimensions [1])

Output = 20

Advantages:

 Faster than lists (since immutable)

 Safer for storing fixed data

Dictionary
A dictionary is an unordered, mutable collection of key-value pairs. Each
key must be unique and immutable (like strings, numbers, or tuples).
Dictionaries are written using curly braces {}. They are commonly used to
store data like student records, configurations, or any structured data.

37
Common methods:

 get () – safely gets a value by key

 keys () – returns all keys

 values () – returns all values

 items () – returns all key-value pairs

 update () – updates the dictionary with another dictionary

Example:

python

student = {"name": "Alice", "age": 20, "grade": "A"}

print(student["name"])

Output = Alice

Use Cases:

 Storing structured data (e.g., JSON-like)

 Fast lookups based on keys

 Grouping related values together

Set
A set is a collection of unordered, unique items. Sets are useful when you
want to ensure there are no duplicate entries. Sets are mutable, meaning you
can add or remove elements, but they do not support indexing or slicing
because they are unordered. Sets are ideal for operations like union,
intersection, and difference between groups.

Common methods:

 add () – adds an element

 remove () – removes an element

 union () – combines two sets

 intersection () – finds common elements

 difference () – elements in one set but not another

Example:

python

set1 = {1, 2, 3}

38
set2 = {3, 4, 5}

print (set1 & set2)

Output = {3}

39
Chapter: 11
Files and File Handling in Python
Files and File Handling in Python
In Python, file handling allows you to create, read, write, and delete files
directly from your Python program. This is especially useful when you want
to store data permanently, process text files, or interact with external files like
logs, reports, or configurations. Python provides built-in functions for file
handling, and the most common one is the open () function. This function is
used to open a file and returns a file object, which lets you perform various
operations on the file.

When opening a file, you must specify the mode:

 "r" – Read (default mode; file must exist)

 "w" – Write (creates a new file or overwrites if it exists)

 "a" – Append (adds data to the end of the file)

 "x" – Create (creates a file, returns error if file exists)

 Add "b" for binary mode (e.g., "rb" for read binary)

 Add "+" to read and write ("r+", "w+", etc.)

To read data from a file, you can use:

 read () – reads the entire file as a string

 readline () – reads one line at a time

 readlines () – reads all lines and returns a list

To write to a file, use write () or writelines (). After you're done working with a
file, it’s important to close it using close () to free up system resources.
However, the better way to handle files in Python is using a with block (also
called a context manager), which automatically closes the file when done.
Example (writing and reading a file):

python

# Writing to a file

with open ("example.txt", "w") as file:

file.write ("Hello, this is a test file.\n")

file.write("Python is fun!")

40
# Reading from a file

with open ("example.txt", "r") as file:

content = file.read()

print(content)

Advantages of Python's file handling include simplicity, cross-platform


compatibility, and powerful tools for both text and binary file operations. It is
widely used in data processing, saving logs, creating reports, and handling
user inputs.

41
Chapter: 12
Regular Expressions in Python
Regular Expressions (commonly abbreviated as RegEx) are powerful tools
used in Python to search, match, and manipulate strings based on specific
patterns. They are especially useful when you need to validate input (like
emails or phone numbers), extract specific parts of text, or perform complex
text replacements. Python provides the re module for working with regular
expressions. To use it, you must import it with import re.

At the core of regular expressions are patterns made up of special


characters. Some common ones include:

 . – matches any character except newline

 ^ – matches the start of a string

 $ – matches the end of a string

 * – matches 0 or more repetitions

 + – matches 1 or more repetitions

 ? – matches 0 or 1 repetition

 [] – matches any one character inside the brackets

 \d – matches any digit (0-9)

 \w – matches any alphanumeric character

 \s – matches any whitespace character

Common functions in the re module:


 re.match () – checks for a match only at the beginning of a string

 re.search() – searches the whole string for the first match

 re.findall() – returns all non-overlapping matches as a list

 re.sub() – replaces matched patterns with a new string

 re.compile() – compiles a regular expression pattern for reuse

Example:

python

import re

42
text = "My phone number is 9876543210"

pattern = r"\d {10}” # matches exactly 10 digits

match = re.search(pattern, text)

if match:

print ("Phone number found:", match. group ()) # Output: 9876543210

Regular expressions can be tricky at first, but they are incredibly powerful
once mastered. You can build anything from simple string filters to complex
parsers. Python also allows the use of flags like re.IGNORECASE or
re.MULTILINE to control how matching is done.

43
CHAPTER : 13
CONCLUSION
Data Science stands at the forefront of the digital revolution, playing a pivotal
role in transforming raw data into meaningful insights that drive strategic
decisions. It is a multidisciplinary field that blends mathematics, statistics,
programming, and domain knowledge to solve real-world problems. From
healthcare and finance to agriculture and entertainment, data science is being
used to optimize operations, predict future trends, personalize user
experiences, and automate tasks through artificial intelligence and machine
learning.

As the volume of data generated continues to grow at an unprecedented rate,


the demand for skilled data scientists is also increasing rapidly. Tools like
Python, R, SQL, and big data technologies such as Hadoop and Spark have
become essential in managing and analyzing vast datasets efficiently.
Moreover, advancements in deep learning and natural language processing
have opened up new possibilities, enabling machines to understand human
language, recognize images, and even make autonomous decisions.

However, with great power comes great responsibility. It is crucial to address


challenges related to data privacy, security, bias, and ethical use. Data
scientists must not only focus on technical accuracy but also consider the
societal implications of their work.

In conclusion, data science is more than just a technical field—it is a catalyst


for innovation and a bridge between data and meaningful action. As
technology evolves, those equipped with strong analytical skills, curiosity, and
ethical awareness will be at the forefront of shaping a smarter, more data-
driven world.

44
CERTIFICATE FROM INTERN ORGANIZATION

v
DECLARATION

I hereby declare that the work presented in this report titled


"PYTHON COURSE Internship Report" is the result of my own
research and study during the internship period at
SKILLDZIRE, undertaken from 16-DEC-2024 to 12-APR-2025.
This report is being submitted in partial fulfilment of the
requirements for the completion of my B.TECH, VISAKHA
INSTITUTE OF ENGINEERING AND
TECHNOLOGY
AFFLIATED TO JNTUGV. All the information, data and results
included in this report are genuine and have been collected,
analyzed, and interpreted by me. Any references or
contributions made by other authors or researchers have
been duly acknowledged in the form of citations and
references. I also confirm that this report has not been
submitted elsewhere for the award of any degree, diploma, or
certificate.

Place: Visakhapatnam Y. ANAND

Date: (21NT1A0458)

vi
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have
supported and guided me throughout my Python Course internship. My
heartfelt thanks to Skill Dzire Organization for providing me with the
opportunity to work and enhance my skills in the field of Python course. I am
deeply thankful to Visakha Institute of Engineering & Technology (VIET)
for offering a supportive environment that made this experience possible. I
extend my sincere appreciation to Dr. G. Satyanarayana, Chairman of VIET,
for his visionary leadership, and Dr. G.V. Pradeep Varma, Principal of VIET,
for his continuous encouragement. I would also like to thank Dr. D. Santha
Rao, Dean of Academics, for his insightful guidance, and Dr. P. Varma,
Training and Placement Officer (TPO), for his efforts in facilitating this
internship. My thanks are also due to Dr. B. Jeevana Rao, Head of the
Department of Electronics and Communication Engineering (ECE), for his
academic support. I am especially grateful to my Project Guide, Mrs. K.
KANTHI KINNERA M. tech, (Ph . D), for her valuable mentorship, constant
encouragement, and expert guidance throughout the internship. Additionally,
I would like to acknowledge the faculty members of the ECE department
whose teachings and support have played a crucial role in my academic
development.

vii
ABSTRACT
Data science encompasses a set of principles, problem definitions, algorithms,
and processes for extracting nonobvious and useful patterns from large data
sets. Many of the elements of data science have been developed in related
fields such as machine learning and data mining. In fact, the terms data
science, machine learning, and data mining are often used interchangeably.
The commonality across these disciplines is a focus on improving decision
making through the analysis of data. However, although data science borrows
from these other fields, it is broader in scope. Machine learning (ML) focuses
on the design and evaluation of algorithms for extracting patterns from data.
Data mining generally deals with the analysis of structured data and often
implies an emphasis on commercial applications. Data science takes all of
these considerations into account but also takes up other challenges, such as
the capturing, cleaning, and transforming of unstructured social media and
web data; the use of big-data technologies to store and process big,
unstructured data sets; and questions related to data ethics and regulation.

viii
CONTENTS
S.NO Name of the Topic/Chapter Page No. From
To

1 Introduction to Artificial Intelligence 1-4


What is AI 1
How AI Works 1
Types of AI 2
Training models of AI 3
Benefits of AI 4
Applications of AI 4
2 Introduction to Data Science 5-8
What is Data Science 5
Where Data Science Needed 5
What is Data, Types of Data 6
How Does a Data Scientist Work 8
Applications Of Data science 8
3 Machine Learning Concepts and Applications 9-10
Why do we need Machine Learning 9
What Makes a Machine learn 9
Benefits of Machine Learning 10
Challenges of Machine Learning 10
4 Introduction to Python for AI & Data Science 11-12
Why python for data science 11
Python Important Features & Interfaces 11
Advantages and disadvantages of python 12
Difference between Python and R Language 12
5 Python Basics and Syntax, Operators & Control 13-23
Statements
Syntax of Python 14
Data Types & Special Characters 15

ix
Operators 17
Strings in Python 19
6 Functions and Scope in Python 24-26
Functions of Python 24
Scopes of python 25
7 Packages & Modules in Python 27-29
8 Exception Handling in Python 30-32
9 Python Data Structures Overview 33-35
10 Lists, Strings, Sets, Tuples, and Dictionaries in 36-39
Python
11 Files and File Handling in Python 40-41
12 Regular Expressions in Python 42-43
13 CONCLUSION 44

x
CHAPTER 1
INTRODUCTION TO AI

Fig1.0

1.1 What is ARTIFICIAL INTELLIGENCE:


Artificial intelligence (AI) is a set of technologies that enable computers to
perform a variety of advanced functions, including the ability to see,
understand and translate spoken and written language, analyse data,
make recommendations, and more.

AI is the backbone of innovation in modern computing, unlocking value


for individuals and businesses. For example, optical character
recognition (OCR) uses AI to extract text and data from images and
documents, turns unstructured content into business-ready structured
data, and unlocks valuable insights. Artificial intelligence is a field of
science concerned with building computers and machines that can
reason, learn, and act in such a way that would normally require human
intelligence or that involves data whose scale exceeds what humans can
analyse.

1.2 HOW AI WORKS:

Fig1.1

1
1.3 Types of Artificial Intelligence:
Artificial intelligence can be organized in several ways, depending on
stages of development or actions being performed.

For instance, four stages of AI development are commonly recognized.

Reactive machines: Limited AI that only reacts to different kinds of


stimuli based on preprogrammed rules. Does not use memory and thus
cannot learn with new data. IBM’s Deep Blue that beat chess champion
Garry Kasparov in 1997 was an example of a reactive machine.

Limited memory: Most modern AI is considered to be limited memory.


It can use memory to improve over time by being trained with new data,
typically through an artificial neural network or other training model.
Deep learning, a subset of machine learning, is considered limited
memory artificial intelligence time

Theory of mind: Theory of mind AI does not currently exist, but


research is ongoing into its possibilities. It describes AI that can
emulate the human mind and has decision-making capabilities equal
to that of a human, including recognizing and remembering emotions
and reacting in social situations as a human would.

Self-aware: A step above theory of mind AI, self-aware AI describes a


mythical machine that is aware of its own existence and has the
intellectual and emotional capabilities of a human. Like theory of mind
AI, self-aware AI does not currently exist.

Fig 1.2

2
1.4 Artificial Intelligence Training Models:
Supervised learning is a machine learning model that maps a specific
input to an output using labelled training data (structured data).

Unsupervised learning is a machine learning model that learns


patterns based on unlabelled data (unstructured data). Unlike
supervised learning, the end result is not known ahead of time. Rather,
the algorithm learns from the data, categorizing it into groups based on
attributes. For instance, unsupervised learning is good at pattern
matching and descriptive modelling.

In addition to supervised and unsupervised learning, a mixed approach


called semi-supervised learning is often employed, where only some of
the data is labelled. In semi-supervised learning, an end result is
known, but the algorithm must figure out how to organize and structure
the data to achieve the desired results.

Fig 1.3

3
1.5 Benefits of AI:

Fig 1.4
1.6 Applications of AI:

Fig 1.5

4
CHAPTER : 2
What is Data Science
Data Science is a combination of multiple disciplines that uses statistics,
data analysis, and machine learning to analyse data and to extract
knowledge and insights from it.

Data Science is about data gathering, analysis and decision-


making.

Data Science is about finding patterns in data, through analysis, and make
future predictions.

 By using Data Science, companies are able to make:


 Better decisions (should we choose A or B)
 Predictive analysis (what will happen next?)
 Pattern discoveries (find pattern, or maybe hidden information in the
data)

2.1 Where is Data Science Needed:


 For route planning: To discover the best routes to ship
 To foresee delays for flight/ship/train etc. (through predictive
analysis)
 To create promotional offers
 To find the best suited time to deliver goods
 To forecast the next years revenue for a company
 To analyse health benefit of training
 To predict who will win elections

Data Science can be applied in nearly every part of a business where data is
available. Examples are:

 Consumer goods
 Stock markets
 Industry
 Politics
 Logistic companies
 E-commerce

2.2 What is Data:


Data is a collection of information.

5
One purpose of Data Science is to structure data, making it
interpretable and easy to work with.

Data can be categorized into two groups:

 Structured data
 Unstructured data

Fig 2.1
2.3 How Does a Data Scientist Work:
A Data Scientist requires expertise in several backgrounds:

 Machine Learning
 Statistics
 Programming (Python or R)
 Mathematics
 Databases

6
Fig 2.2
1. Problem Statement:

No work starts without motivation, Data science is no exception though.


It’s really important to declare or formulate your problem statement
very clearly and precisely. Your whole model and it’s working depend
on your statement. Many scientists consider this as the main and much
important step of Date Science. So, make sure what’s your problem
statement and how well can it add value to business or any other
organization.

2. Data Collection:

After defining the problem statement, the next obvious step is to go in


search of data that you might require for your model. You must do good
research, find all that you need. Data can be in any form i.e.
unstructured or structured. It might be in various forms like videos,
spreadsheets, coded forms, etc. You must collect all these kinds of
sources.

3. Data Cleaning:

As you have formulated your motive and also you did collect your data,
the next step to do is cleaning. Yes, it is! Data cleaning is the most
favourite thing for data scientists to do. Data cleaning is all about the
removal of missing, redundant, unnecessary and duplicate data from
your collection. There are various tools to do so with the help of
programming in either R or Python. It’s totally on you to choose one of
them. Various scientist has their opinion on which to choose. When it
comes to the statistical part, R is preferred over Python, as it has the
privilege of more than 12,000 packages. While python is used as it is
fast, easily accessible and we can perform the same things as we can in
R with the help of various packages.

4. Data Analysis and Exploration:

7
It’s one of the prime things in data science to do and time to get inner
Holmes out. It’s about analysing the structure of data, finding hidden
patterns in them, studying behaviours, visualizing the effects of one
variable over others and then concluding. We can explore the data with
the help of various graphs formed with the help of libraries using any
programming language. In R, GGplot is one of the most famous models
while Matplotlib in Python.

5. Data Modelling:

Once you are done with your study that you have formed from data
visualization, you must start building a hypothesis model such that it
may yield you a good prediction in future. Here, you must choose a good
algorithm that best fit to your model. There different kinds of algorithms
from regression to classification, SVM (Support vector machines),
Clustering, etc. Your model can be of a Machine Learning algorithm.
You train your model with the train data and then test it with test data.
There are various methods to do so. One of them is the K-fold method
where you split your whole data into two parts, one is Train and the
other is test data. On these bases, you train your model.

6. Optimization and Deployment:

You followed each and every step and hence build a model that you feel
is the best fit. But how can you decide how well your model is
performing? This where optimization comes. You test your data and find
how well it is performing by checking its accuracy. In short, you check
the efficiency of the data model and thus try to optimize it for better
accurate prediction. Deployment deals with the launch of your model
and let the people outside there to benefit from that. You can also obtain
feedback from organizations and people to know their need and then to
work more on your model.

2.4 Applications of Data Science:

Fig 2.3

8
CHAPTER : 3
Machine Learning concepts and Applications
Machine learning (ML) allows computers to learn and make decisions without
being explicitly programmed. It involves feeding data into algorithms to
identify patterns and make predictions on new data. Machine learning is used
in various applications, including image and speech recognition, natural
language processing, and recommender systems.

3.1 Why do we need Machine Learning?


Machine Learning algorithm learns from data, trains on patterns, and
solves or predicts complex problems beyond the scope of traditional
programming. It drives better decision-making and tackles intricate
challenges efficiently.

 Solving Complex Business Problems


 Handling Large Volumes of Data
 Automate Repetitive Tasks
 Personalized User Experience
 Self-Improvement in Performance

3.2 What Makes a Machine “Learn”?


A machine “learns” by recognizing patterns and improving its
performance on a task based on data, without being explicitly
programmed.

The process involves:

Data Input: Machines require data (e.g., text, images, numbers) to


analyse.
Algorithms: Algorithms process the data, finding patterns or
relationships.

Model Training: Machines learn by adjusting their parameters based


on the input data using mathematical models.

Feedback Loop: The machine compares predictions to actual outcomes


and corrects errors (via optimization methods like gradient descent).

Experience and Iteration: Repeating this process with more data


improves the machine’s accuracy over time.

Evaluation and Generalization: The model is tested on unseen data


to ensure it performs well on real-world tasks.

9
3.3 Importance of Data in Machine Learning:
Data is the foundation of machine learning (ML). Without quality data,
ML models cannot learn, perform, or make accurate predictions.

 Data provides the examples from which models learn patterns


and relationships.
 High-quality and diverse data improves model accuracy and
generalization.
 Data ensures models understand real-world scenarios and adapt
to practical applications.
 Features derived from data are critical for training models.
 Separate datasets for validation and testing assess how well the
model performs on unseen data.
 Data fuels iterative improvements in ML models through
feedback loops.

Fig 3.0

3.5 Challenges of Machine Learning:

Fig 3.1

10
CHAPTER : 4
PYTHON
Python is a programming language widely used by Data Scientists.

Python has in-built mathematical libraries and functions, making it easier to


calculate mathematical problems and to perform data analysis.

4.1 Why Python for Data Science?


Python is favoured in data science due to its readability, simplicity, and
versatility. Its extensive libraries and frameworks streamline complex
tasks, allowing data scientists to focus on problem-solving rather than
coding intricacies.

Fig 4.1

4.2 Features of Python:

Fig 4.2

11
4.3 Key Libraries and Tools:
NumPy: A fundamental library for numerical operations in Python,
supporting large, multi-dimensional arrays and matrices.

pandas: A powerful library for data manipulation and analysis, offering


data structures like Data Frames to handle structured data efficiently.

Scikit-learn: A comprehensive library for machine learning, providing


simple and efficient data mining and analysis tools.

Matplotlib and Seaborn: Libraries for creating static, animated, and


interactive visualizations, helping to understand data patterns and
trends

Fig 4.3

4.4 Advantages and Disadvantages of Python:

Fig 4.4

12
4.5 Applications of Python:

Fig 4.5

Benefits of Python:

Fig 4.6

4.6 Difference between Python and R Language

Fig 4.7

13
CHAPTER: 5
Python Syntax, Data Types & Operators
Python is known for its clean and readable syntax, which makes it an
excellent language for beginners and professionals working in AI, data
science, and software development.

5.1 Python Syntax


Python syntax refers to the set of rules that define how a Python program is
written and interpreted. One of the most distinctive and beginner-friendly
aspects of Python is its clean and readable syntax. Unlike many other
programming languages that use curly braces {} to define code blocks, Python
uses indentation (whitespace). This means that consistent indentation is not
just a style, but a requirement in Python—usually 4 spaces are used per
indentation level.

A Python program is made up of statements and expressions. Statements are


instructions (like if, for, or def) that perform actions, while expressions are
combinations of values and operators that evaluate to a result. Python is case-
sensitive, so Name, name, and NAME are all treated as different identifiers.

Some key points of Python syntax:

Comments start with # and are ignored by the interpreter. Use them to explain
your code.
Variables do not require a type declaration; the type is inferred from the value
(e.g., x = 10).

Functions are defined using the def keyword, and blocks of code are
structured using colons (:) followed by indented lines.

Control structures like if, elif, else, for, and while are written in a natural,
readable way.

Importing modules is done using the import keyword.

Example:

# This is a comment

def greet(name):

if name:

print (f"Hello, {name}!")

else:

14
print ("Hello, Guest!")

greet("Alice")

Python also supports a REPL (Read-Eval-Print Loop) mode, where you can
type Python code line by line and see immediate results. This makes it great
for quick testing and learning. Overall, Python's syntax emphasizes
readability, simplicity, and consistency, which is why it's so widely loved by
beginners and professionals alike.

Fig 5.1

5.2 Python Data Types:


In Python, data types define the kind of value a variable can hold, and they
are essential for writing correct and efficient programs. Python is a
dynamically typed language, which means you don't need to declare the data
type of a variable explicitly—Python detects it automatically at runtime. The
built-in data types in Python can be broadly categorized into several types:

15
◆ 1. Numeric Types

These include:

int – for integers (e.g., 10, -5)

float – for decimal numbers (e.g., 3.14, -0.01)

complex – for complex numbers (e.g., 2 + 3j)

◆ 2. Sequence Types

These are ordered collections:

str – string, a sequence of characters (e.g., "Hello")

list – mutable sequence of items (e.g., [1, 2, 3])

tuple – immutable sequence (e.g., (4, 5, 6))

◆ 3. Set Types

set – unordered collection of unique items (e.g., {1, 2, 3})

frozen set – like a set but immutable

◆ 4. Mapping Type

dict – a collection of key-value pairs (e.g., {"name": "Alice", "age": 25})

◆ 5. Boolean Type

bool – represents True or False, typically used in conditional expressions

◆ 6. Binary Types

Used to handle binary data:

bytes – immutable sequence of bytes

bytearray – mutable sequence of bytes

memoryview – memory-efficient view of bytes

16
◆ 7. None Type

NoneType – represents the absence of a value, written as None

Example:

a = 10 # int

b = 3.14 # float

c = "Python" # str

d = [1, 2, 3] # list

e = {"key": 1} # dict

f = True # bool

Python also allows you to check the type of a variable using the built-in type()
function, and you can convert between types using type casting, such as int(),
float(), str(), etc. Understanding data types is foundational for writing correct
Python code, as operations and functions behave differently depending on the
type of data they work with.

5.3 Operators:
In Python, operators are special symbols or keywords used to perform
operations on variables and values. Python supports several types of
operators that enable arithmetic operations, comparisons, logical decisions,
bitwise manipulations, and more. These operators make it easier to write
expressions that carry out calculations and control flow in programs.

1. Arithmetic Operators

Used to perform basic mathematical operations:

+ (Addition), - (Subtraction), * (Multiplication), / (Division)

// (Floor Division), % (Modulus), ** (Exponentiation)

Example:

a=5

b=2

print (a + b) # 7

print (a ** b) # 25

2. Comparison (Relational) Operators

17
Used to compare values and return a boolean result:

== (Equal to),!= (Not equal to)

> (Greater than), < (Less than)

>= (Greater than or equal to), <= (Less than or equal to)

Example:

x = 10

y = 20

print (x < y) # True

3. Logical Operators

Used to combine conditional statements:

and – True if both conditions are true

or – True if at least one condition is true

not – Reverses the result (True becomes False)

Example:

a=5

print (a > 2 and a < 10) # True

4. Assignment Operators

Used to assign values to variables:

=, +=, -=, *=, /=, %=, **=, //=

Example:

x=5

x += 3 # x becomes 8

5. Bitwise Operators

Used to perform operations on binary representations:

& (AND), | (OR), ^ (XOR)

~ (NOT), << (Left Shift), >> (Right Shift)

18
Example:

a=5 # 0101

b=3 # 0011

print (a & b) # 1 (0001)

6. Membership Operators

Used to test if a value is a member of a sequence (like list, string, tuple):

in – returns True if value exists

not in – returns True if value does not exist

Example:

fruits = ["apple", "banana"]

print ("apple" in fruits) # True

7. Identity Operators

Used to compare memory locations of objects:

is – returns True if two variables point to the same object

is not – returns True if they do not

Example:

x = [1, 2, 3]

y=x

print (x is y) # True

5.4 Control Statements:


Control statements in Python are used to manage the flow of execution in a
program. They allow you to make decisions, repeat actions, or jump out of
certain code blocks based on conditions. The three main types of control
statements are conditional statements, looping statements, and loop control
statements.

◆ Conditional Statements
These statements let your program make decisions based on certain
conditions. Python uses:

19
if – executes a block if the condition is true

elif – checks another condition if the previous one was false

else – executes a block if all previous conditions were false

Example:

x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

◆ Looping Statements
Loops are used to repeat a block of code multiple times.

for loop – iterates over a sequence (like a list, string, or range)

while loop – repeats as long as a condition is true

Examples:

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

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

◆ Loop Control Statements


These are used to alter the flow inside loops:

break – exits the loop immediately

continue – skips the rest of the current iteration

20
pass – does nothing, used as a placeholder

Example:

for i in range (5):


if i == 3:
break
print(i) # prints 0, 1, 2

for i in range (5):


if i == 3:
continue
print(i) # prints 0, 1, 2, 4
Control statements are the backbone of decision-making and repetition in
Python, making it possible to write intelligent, responsive, and efficient
programs.

5.4 Strings in Python:


Strings in Python

In Python, a string is a sequence of characters used to represent textual data


such as words, sentences, or even numbers written as text. Strings are
enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """) for
multi-line strings. Python strings are immutable, meaning once a string is
created, its characters cannot be changed individually—you can only create a
new string through operations. Strings support a variety of operations like
concatenation, slicing, and iteration, and are widely used in almost every
Python program.

Python offers many powerful string methods to work with text, such as:

upper () – converts to uppercase

lower () – converts to lowercase

title () – capitalizes each word

21
strip () – removes whitespace from both ends

replace (old, new) – replaces parts of the string

split () – splits the string into a list

join () – joins elements of a list into a single string

find () – returns the index of the first match

startswith () / endswith () – checks how a string begins or ends

Example:

text = “Python is awesome! “

print(text.strip().upper()) # Output: PYTHON IS AWESOME!

Strings can also be indexed and sliced:

word = "Python"

print(word[0]) # P (first character)

print(word[-1]) # n (last character)

print (word [1:4]) # yth (slicing from index 1 to 3)

Python also supports string formatting, which allows you to embed variables
into strings:

Using f-strings: f"Hello, {name}!"

Using .format(): "Hello, {}”. format(name)

Using % formatting (older style): "Hello, %s" % name

A string is a sequence of characters which is enclosed in quotes.

22
There are basically 3 types of operators supported by string:

 Basic Operators: There are two types of basic operators in string. They are
“+” and “*”.
1. Concatenation Operator (+): the concatenation operator concatenates
two strings and forms a new string.
2. Replication Operator (*): It is used to repeat a string number of times
the string will be repeated the number of times is given by the integer
value.
 Membership operators: To test whether a value is present in a sequence.
 Relational Operators: All the comparisons operators i.e., (<,>, <=,>=, == ,!=,
<>)
 Slice Notation: String Slice can be defined as substring which is the part of
string. Therefore, further substring can be obtained from a string.

Strings in Python are versatile and essential, used in everything from simple
output messages to file handling, data parsing, and user input. Their
flexibility and the wide range of methods make them one of the most
important data types in Python.

23
CHAPTER:6
Functions and Scope in Python
In Python: functions, modules, and exception handling. These concepts help
developers write organized, reusable, and error-free code, making Python a
powerful and efficient programming language for AI, data science, and
software development.

6.1 Functions in Python:


Functions in Python

In Python, a function is a reusable block of code that performs a specific task.


Functions help organize code, make it more readable, reduce repetition, and
allow for modular programming. You can define a function using the def
keyword, followed by the function name and parentheses (), which may
include parameters—placeholders for the inputs the function can receive. The
code inside the function is indented and runs only when the function is called.
If a function should return a result, you use the return statement. In

• Built-in Functions such as print (), len (), and range ().

• User-defined Functions, where programmers create their own functions


using the def

keyword.

• Function Parameters and Return Values, enabling functions to accept


input and return

output for better flexibility.

• Lambda Functions, which are small anonymous functions used for quick,
short operations.

Example:

def greet(name):

return f"Hello, {name}!"

print(greet("Alice")) # Output: Hello, Alice!

Python also supports default arguments, where parameters can have default
values:

24
python

Copy

Edit

def greet(name="Guest"):

print (f"Welcome, {name}!")

Functions can take any number of arguments using:

*args for variable-length positional arguments

**kwargs for variable-length keyword arguments

Python also allows anonymous functions using the lambda keyword. These
are short, one-line functions used for simple tasks, especially with functions
like map (), filter (), and sorted ().

Example:

square = lambda x: x * x

print (square (5)) # Output: 25

6.2 Scopes of Python


In Python, scope refers to the visibility and accessibility of variables
within different parts of a program. Scope determines where a variable
is accessible and where not. In order to understand how variables
behave within functions and how they interact with each other, it is
crucial to understand scope.

Python has two main types of scope:

Local scope:
 Variables declared within a function have local scope. They are
accessible only within the function in which they are defined.
 Local variables are created when the function is called and
destroyed when it exits.
 Local variables cannot be accessed from outside the function.

25
Global Scope:
 Variables declared outside of any function or at the top level of a
script have global scope. They are accessible throughout the
program.
 During program startup, global variables are created in memory
and remain there until the program ends.
 Global variables can be accessed from any function within the
program.

Nested scope:
 Python allows nested functions, where one function is defined
inside another.
 During nested functions, the inner function has access to
variables in the outer (enclosed) function.
 The inner function's scope is called "nested scope" because it
includes both its local scope and the enclosing function's scope.

26
CHAPTER: 7
Packages and Modules in Python
Introduction
Python is a high-level, general-purpose programming language widely used in
various domains including data science, machine learning, web development,
and automation. One of Python’s key strengths is its modular structure,
which allows developers to organize code into reusable components. This
modularity is achieved through the use of modules and packages, which play
a vital role in organizing, maintaining, and scaling Python projects effectively.

Modules in Python
A module is a file containing Python code that is written for reuse. It typically
consists of functions, classes, and variables that serve specific functionalities.
The primary goal of a module is to break down large programs into smaller,
manageable, and logically organized parts. This enhances code readability,
promotes reuse, and simplifies debugging and maintenance.

Modules form the foundational building blocks of Python programs. They can
be standard (built-in to Python), third-party (installed externally), or user-
defined (created by the developer). Using modules also allows for separation
of concerns, where each module is responsible for a specific part of the
program logic, reducing complexity in large codebases.

27
Packages in Python
A package is a hierarchical file structure that contains multiple modules
grouped together to form a collection of related functionalities. Packages allow
developers to organize their modules into directories, thereby creating a
scalable project structure. The presence of a special initialization file in the
directory indicates to Python that it should treat the directory as a package.

Packages are essential when working on large projects that involve multiple
components. By categorizing similar modules into packages, developers can
avoid naming conflicts, improve code organization, and enable better
navigation through the codebase. Packages can also contain sub-packages,
allowing for multi-level structuring of code.

Advantages of Using Modules and Packages

The use of modules and packages provides several benefits in software


development:

 Reusability: Code can be written once and reused in different


programs.

 Maintainability: Issues can be isolated and fixed within individual


modules or packages.

 Readability: Well-structured code is easier to understand and modify.

 Namespace Management: Helps avoid conflicts by isolating function


and variable names.

 Scalability: Supports growth of codebase in an organized manner,


especially in large projects.

In professional environments, especially in domains like data science,


modular programming with well-organized packages and modules is
considered a best practice.

Relevance in Data Science


In the field of data science, modular code organization is crucial due to the
multifaceted nature of tasks such as data preprocessing, analysis,
visualization, and model evaluation. Data scientists frequently work with
various Python packages designed for specific tasks. Understanding the
structure and use of modules and packages enables data scientists to build
efficient, reusable, and well-organized code pipelines.

During the course of my internship in the domain of data science, I learned


the importance of modular programming when dealing with data workflows.
The use of packages and modules made it easier to manage code, automate

28
repetitive processes, and collaborate effectively in a team environment. This
approach not only improved the quality of the code but also enhanced overall
productivity.
Modules in Python are essential components that allow programmers to
organize code into separate files and reuse functionality across different
programs. A module is simply a file containing Python code—such as
functions, classes, or variables—that can be imported and used in another
Python script. Python supports various types of modules, including built-in
modules like math, os, and datetime, which come pre-installed and provide
powerful features for mathematical operations, file handling, and date/time
manipulation. Users can also create their own custom modules, known as
user-defined modules, to structure their code better and enhance reusability.
Additionally, third-party modules like numpy, pandas, matplotlib, and flask
can be installed using Python’s package manager pip to perform specific tasks
such as data analysis, visualization, and web development. Modules can be
imported using the import statement, and specific functions or classes can be
brought in using from module import name. By using modules, Python
promotes modular programming, which leads to cleaner, more manageable
code, encourages reusability, reduces redundancy, and improves overall
program structure. Whether for small scripts or large applications, modules
play a vital role in efficient and effective Python development.

29
CHAPTER: 8
EXCEPTION HANDLING IN PYTHON
Introduction
In any programming language, errors are a natural part of the development
process. Python provides a structured way to detect and handle these errors
using a mechanism called exception handling. This allows programs to
respond to unexpected situations without crashing, thereby improving
robustness, user experience, and overall software reliability.

Exception handling is a critical concept in Python, particularly in data-driven


applications where unpredictable user input, file errors, or network issues
can arise. Effective handling of exceptions ensures smooth execution and
helps in debugging, logging, and maintaining code efficiently.

Understanding Exceptions
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions are not necessarily errors
in logic; they often result from conditions that are beyond the control of the
program, such as attempting to access a file that does not exist or dividing a
number by zero.

In Python, exceptions are objects that represent these error conditions. When
an exception occurs, Python immediately stops the current flow of the
program and looks for a way to handle the exception. If not handled, the
program terminates and displays an error message, commonly referred to as
a traceback.

Exception Handling Mechanism


Python uses a structured approach to manage exceptions through specific
keywords that help detect and respond to exceptions. The handling
mechanism allows developers to define blocks of code to try and detect errors,
and to define alternative behaviours in case an error occurs. This approach
separates normal program logic from error handling, which leads to clearer
and more maintainable code.

The exception handling structure in Python includes the following:

 A block to attempt execution.

 One or more blocks to handle specific or general exceptions.

 An optional block that executes regardless of whether an exception


occurred.

30
 An optional block for cleanup actions.

This mechanism provides flexibility and control over how different types of
exceptions are managed and ensures that the program can continue running
or exit gracefully.

Benefits of Exception Handling


Proper use of exception handling brings multiple benefits to Python programs,
especially in complex or user-facing applications. Some key advantages
include:

 Error Isolation: Helps identify exactly where the error occurred without
affecting the rest of the code.

 Improved User Experience: Allows for graceful failure and user-friendly


error messages instead of program crashes.

 Code Clarity: Separates normal program logic from error handling,


making code cleaner and easier to understand.

 System Stability: Prevents unexpected terminations by managing rare


or unanticipated situations safely.

 Maintenance & Debugging: Makes the program easier to maintain and


debug by providing detailed error messages and control flow.

Exception Hierarchy and Custom Exceptions


Python’s built-in exception classes are arranged in a hierarchy, starting from
a base class. This structure allows developers to catch a broad category of
errors or target specific ones. Additionally, Python allows developers to define
their own custom exceptions by creating new classes. This is especially useful
in larger projects, including data science applications, where domain-specific
errors need to be clearly identified and handled.

Custom exception handling improves code readability and gives a clearer


understanding of how certain errors are treated uniquely, contributing to
better error tracking and documentation.

Relevance in Data Science


In the domain of data science, exception handling is crucial due to the
unpredictability of data sources and system resources. Whether it is reading
from external files, processing real-time data, or interacting with APIs,
exceptions can occur at multiple stages. Proper handling ensures that data
pipelines do not break due to a single failure and that logs are maintained for
future analysis.

31
During my internship in the field of data science, I encountered several
scenarios where exception handling became necessary—for instance, when
handling missing values, managing file loading issues, or connecting to
external databases. Implementing structured exception handling helped me
build resilient scripts that could run reliably in different environments with
varying data inputs.

Conclusion
Exception handling is a fundamental aspect of writing robust and
professional-grade Python applications. It allows developers to anticipate and
manage errors effectively, ensuring that programs behave predictably even
under unexpected conditions. In data science and other real-world
applications, the ability to handle exceptions gracefully not only improves
performance but also enhances the reliability and trustworthiness of the
system. My internship experience underscored the importance of mastering
exception handling to create stable, scalable, and user-friendly Python
solutions.

32
CHAPTER: 9
PYTHON DATA STRCTURES
Introduction
Data structures are the foundational building blocks of any programming
language. In Python, data structures are used to store, organize, and manage
data efficiently. They provide a means of performing operations on data and
are essential for solving complex computational problems. Python offers a rich
collection of built-in data structures that are both flexible and easy to use,
which makes the language especially powerful for data science and software
development.

Understanding and utilizing Python’s data structures effectively is crucial for


writing optimized and maintainable code. They support efficient data
manipulation, enable clear program logic, and allow for better performance
across a wide range of applications.

Types of Data Structures in Python


Python provides several built-in data structures, each with unique properties,
performance characteristics, and use cases. These can be categorized into two
main types: primitive and non-primitive data structures.

1. Primitive Data Structures

These are the most basic data types in Python, including:

 Integers

 Floats

 Strings

 Booleans
While not considered data structures in the traditional sense, these primitives
form the basis for more complex types.

2. Non-Primitive Data Structures

These include more advanced structures that are capable of storing multiple
elements and performing operations on them. The primary non-primitive data
structures in Python are:

 Lists: Ordered and mutable collections of elements.

 Tuples: Ordered but immutable sequences.

 Sets: Unordered collections of unique elements.

33
 Dictionaries: Key-value pairs for efficient lookup and storage.

Each of these structures is implemented in a way that allows for dynamic


memory management, and they can grow or shrink as needed, which makes
them more flexible than traditional arrays in other languages.

Importance in Programming and Data Science


Efficient use of data structures is essential for solving real-world problems.
They help in organizing data logically and performing operations such as
insertion, deletion, traversal, and searching in a time-efficient manner.
In the context of data science, choosing the right data structure can greatly
impact the performance and scalability of data pipelines and analytical
models. For example, dictionaries are often used for mapping categorical
variables, while lists and tuples are commonly used for storing data records
or feature sets.

Python’s built-in data structures are often used in combination with third-
party libraries like pandas, which extends their functionality for handling
structured data such as tables and time series.

Key Features of Python Data Structures


 Dynamic Typing: Python data structures can hold mixed data types,
adding flexibility during implementation.

 Memory Efficiency: Python manages memory dynamically, which


simplifies development while still allowing efficient performance.

 Ease of Use: The syntax and operations associated with Python’s data
structures are intuitive and user-friendly.

 Rich Functionality: Python provides a wide range of built-in methods


for manipulating data structures, enhancing productivity and code
readability.

 Extensibility: Built-in structures can be extended or customized to


create more complex structures such as stacks, queues, and graphs
using object-oriented programming.

Applications in Real-World Projects


During the course of my internship in data science, I worked with large and
complex datasets requiring structured organization and efficient data
manipulation. Python data structures played a key role in managing this data
effectively.

34
Tasks such as data cleaning, transformation, and aggregation were greatly
facilitated by using dictionaries, lists, and sets. Understanding the underlying
structure of data allowed me to implement faster and more reliable solutions,
especially when dealing with large-scale operations or real-time data.

Data structures also supported integration with various tools and libraries,
enabling seamless development of end-to-end data workflows.

35
Chapter:10
Lists, Tuples, Sets, Dictionaries and Strings in
Python
List
A list in Python is a dynamic, ordered collection that can store elements of
different data types such as integers, floats, strings, or even other lists (nested
lists). Lists are mutable, so you can change, add, or delete elements without
creating a new list. They are defined using square brackets []. Lists are
versatile and widely used for storing a sequence of items such as a list of
student names, shopping items, or daily temperatures.

Common methods include:

 append () – adds an item to the end

 insert () – inserts an item at a specific index

 pop () – removes and returns the last element

 sort () – sorts the list in ascending order

 reverse () – reverses the list

Example:

fruits = ["apple", "banana", "cherry"]


fruits. Append("orange")

print(fruits)

Output = ['apple', 'banana', 'cherry', 'orange']

String
A string is a sequence of Unicode characters used to represent text. Strings
are immutable, meaning once created, their content cannot be changed. You
can perform various operations on strings like slicing, searching, formatting,
and joining. Strings are defined using single ' or double " quotes, and multiline
strings use triple quotes ''' or """.

Common methods include:

 upper () – converts to uppercase

 lower () – converts to lowercase

 find () – finds a substring

36
 replace () – replaces part of the string

 split () – splits the string into a list

Example:

python

message = "Python is fun"

print (message. Upper ())

Output = PYTHON IS FUN

Tuple
A tuple is a collection similar to a list but immutable, meaning once it's
created, you cannot add, remove, or change elements. Tuples are defined
using parentheses (). Because they are immutable, they can be used as
dictionary keys or elements in a set, which lists cannot do. Tuples are
usually used when the data should not be changed throughout the program,
like coordinates (x, y) or months of the year.

Common operations:

 Accessing elements via index

 Iterating with loops

 Using count () and index () methods

Example:

python

dimensions = (10, 20, 30)

print (dimensions [1])

Output = 20

Advantages:

 Faster than lists (since immutable)

 Safer for storing fixed data

Dictionary
A dictionary is an unordered, mutable collection of key-value pairs. Each
key must be unique and immutable (like strings, numbers, or tuples).
Dictionaries are written using curly braces {}. They are commonly used to
store data like student records, configurations, or any structured data.

37
Common methods:

 get () – safely gets a value by key

 keys () – returns all keys

 values () – returns all values

 items () – returns all key-value pairs

 update () – updates the dictionary with another dictionary

Example:

python

student = {"name": "Alice", "age": 20, "grade": "A"}

print(student["name"])

Output = Alice

Use Cases:

 Storing structured data (e.g., JSON-like)

 Fast lookups based on keys

 Grouping related values together

Set
A set is a collection of unordered, unique items. Sets are useful when you
want to ensure there are no duplicate entries. Sets are mutable, meaning you
can add or remove elements, but they do not support indexing or slicing
because they are unordered. Sets are ideal for operations like union,
intersection, and difference between groups.

Common methods:

 add () – adds an element

 remove () – removes an element

 union () – combines two sets

 intersection () – finds common elements

 difference () – elements in one set but not another

Example:

python

set1 = {1, 2, 3}

38
set2 = {3, 4, 5}

print (set1 & set2)

Output = {3}

39
Chapter: 11
Files and File Handling in Python
Files and File Handling in Python
In Python, file handling allows you to create, read, write, and delete files
directly from your Python program. This is especially useful when you want
to store data permanently, process text files, or interact with external files like
logs, reports, or configurations. Python provides built-in functions for file
handling, and the most common one is the open () function. This function is
used to open a file and returns a file object, which lets you perform various
operations on the file.

When opening a file, you must specify the mode:

 "r" – Read (default mode; file must exist)

 "w" – Write (creates a new file or overwrites if it exists)

 "a" – Append (adds data to the end of the file)

 "x" – Create (creates a file, returns error if file exists)

 Add "b" for binary mode (e.g., "rb" for read binary)

 Add "+" to read and write ("r+", "w+", etc.)

To read data from a file, you can use:

 read () – reads the entire file as a string

 readline () – reads one line at a time

 readlines () – reads all lines and returns a list

To write to a file, use write () or writelines (). After you're done working with a
file, it’s important to close it using close () to free up system resources.
However, the better way to handle files in Python is using a with block (also
called a context manager), which automatically closes the file when done.
Example (writing and reading a file):

python

# Writing to a file

with open ("example.txt", "w") as file:

file.write ("Hello, this is a test file.\n")

file.write("Python is fun!")

40
# Reading from a file

with open ("example.txt", "r") as file:

content = file.read()

print(content)

Advantages of Python's file handling include simplicity, cross-platform


compatibility, and powerful tools for both text and binary file operations. It is
widely used in data processing, saving logs, creating reports, and handling
user inputs.

41
Chapter: 12
Regular Expressions in Python
Regular Expressions (commonly abbreviated as RegEx) are powerful tools
used in Python to search, match, and manipulate strings based on specific
patterns. They are especially useful when you need to validate input (like
emails or phone numbers), extract specific parts of text, or perform complex
text replacements. Python provides the re module for working with regular
expressions. To use it, you must import it with import re.

At the core of regular expressions are patterns made up of special


characters. Some common ones include:

 . – matches any character except newline

 ^ – matches the start of a string

 $ – matches the end of a string

 * – matches 0 or more repetitions

 + – matches 1 or more repetitions

 ? – matches 0 or 1 repetition

 [] – matches any one character inside the brackets

 \d – matches any digit (0-9)

 \w – matches any alphanumeric character

 \s – matches any whitespace character

Common functions in the re module:


 re.match () – checks for a match only at the beginning of a string

 re.search() – searches the whole string for the first match

 re.findall() – returns all non-overlapping matches as a list

 re.sub() – replaces matched patterns with a new string

 re.compile() – compiles a regular expression pattern for reuse

Example:

python

import re

42
text = "My phone number is 9876543210"

pattern = r"\d {10}” # matches exactly 10 digits

match = re.search(pattern, text)

if match:

print ("Phone number found:", match. group ()) # Output: 9876543210

Regular expressions can be tricky at first, but they are incredibly powerful
once mastered. You can build anything from simple string filters to complex
parsers. Python also allows the use of flags like re.IGNORECASE or
re.MULTILINE to control how matching is done.

43
CHAPTER : 13
CONCLUSION
Data Science stands at the forefront of the digital revolution, playing a pivotal
role in transforming raw data into meaningful insights that drive strategic
decisions. It is a multidisciplinary field that blends mathematics, statistics,
programming, and domain knowledge to solve real-world problems. From
healthcare and finance to agriculture and entertainment, data science is being
used to optimize operations, predict future trends, personalize user
experiences, and automate tasks through artificial intelligence and machine
learning.

As the volume of data generated continues to grow at an unprecedented rate,


the demand for skilled data scientists is also increasing rapidly. Tools like
Python, R, SQL, and big data technologies such as Hadoop and Spark have
become essential in managing and analyzing vast datasets efficiently.
Moreover, advancements in deep learning and natural language processing
have opened up new possibilities, enabling machines to understand human
language, recognize images, and even make autonomous decisions.

However, with great power comes great responsibility. It is crucial to address


challenges related to data privacy, security, bias, and ethical use. Data
scientists must not only focus on technical accuracy but also consider the
societal implications of their work.

In conclusion, data science is more than just a technical field—it is a catalyst


for innovation and a bridge between data and meaningful action. As
technology evolves, those equipped with strong analytical skills, curiosity, and
ethical awareness will be at the forefront of shaping a smarter, more data-
driven world.

44
DECLARATION

I hereby declare that the work presented in this report titled


"PYTHON COURSE Internship Report" is the result of my own
research and study during the internship period at
SKILLDZIRE, undertaken from 16-DEC-2024 to 12-APR-2025.
This report is being submitted in partial fulfilment of the
requirements for the completion of my B.TECH, VISAKHA
INSTITUTE OF ENGINEERING AND
TECHNOLOGY
AFFLIATED TO JNTUGV. All the information, data and results
included in this report are genuine and have been collected,
analyzed, and interpreted by me. Any references or
contributions made by other authors or researchers have
been duly acknowledged in the form of citations and
references. I also confirm that this report has not been
submitted elsewhere for the award of any degree, diploma, or
certificate.

Place: Visakhapatnam Y. ANAND

Date: (21NT1A0458)

vi
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have
supported and guided me throughout my Python Course internship. My
heartfelt thanks to Skill Dzire Organization for providing me with the
opportunity to work and enhance my skills in the field of Python course. I am
deeply thankful to Visakha Institute of Engineering & Technology (VIET)
for offering a supportive environment that made this experience possible. I
extend my sincere appreciation to Dr. G. Satyanarayana, Chairman of VIET,
for his visionary leadership, and Dr. G.V. Pradeep Varma, Principal of VIET,
for his continuous encouragement. I would also like to thank Dr. D. Santha
Rao, Dean of Academics, for his insightful guidance, and Dr. P. Varma,
Training and Placement Officer (TPO), for his efforts in facilitating this
internship. My thanks are also due to Dr. B. Jeevana Rao, Head of the
Department of Electronics and Communication Engineering (ECE), for his
academic support. I am especially grateful to my Project Guide, Mrs. K.
KANTHI KINNERA M. tech, (Ph . D), for her valuable mentorship, constant
encouragement, and expert guidance throughout the internship. Additionally,
I would like to acknowledge the faculty members of the ECE department
whose teachings and support have played a crucial role in my academic
development.

vii
ABSTRACT
Data science encompasses a set of principles, problem definitions, algorithms,
and processes for extracting nonobvious and useful patterns from large data
sets. Many of the elements of data science have been developed in related
fields such as machine learning and data mining. In fact, the terms data
science, machine learning, and data mining are often used interchangeably.
The commonality across these disciplines is a focus on improving decision
making through the analysis of data. However, although data science borrows
from these other fields, it is broader in scope. Machine learning (ML) focuses
on the design and evaluation of algorithms for extracting patterns from data.
Data mining generally deals with the analysis of structured data and often
implies an emphasis on commercial applications. Data science takes all of
these considerations into account but also takes up other challenges, such as
the capturing, cleaning, and transforming of unstructured social media and
web data; the use of big-data technologies to store and process big,
unstructured data sets; and questions related to data ethics and regulation.

viii
CONTENTS
S.NO Name of the Topic/Chapter Page No. From
To

1 Introduction to Artificial Intelligence 1-4


What is AI 1
How AI Works 1
Types of AI 2
Training models of AI 3
Benefits of AI 4
Applications of AI 4
2 Introduction to Data Science 5-8
What is Data Science 5
Where Data Science Needed 5
What is Data, Types of Data 6
How Does a Data Scientist Work 8
Applications Of Data science 8
3 Machine Learning Concepts and Applications 9-10
Why do we need Machine Learning 9
What Makes a Machine learn 9
Benefits of Machine Learning 10
Challenges of Machine Learning 10
4 Introduction to Python for AI & Data Science 11-12
Why python for data science 11
Python Important Features & Interfaces 11
Advantages and disadvantages of python 12
Difference between Python and R Language 12
5 Python Basics and Syntax, Operators & Control 13-23
Statements
Syntax of Python 14
Data Types & Special Characters 15

ix
Operators 17
Strings in Python 19
6 Functions and Scope in Python 24-26
Functions of Python 24
Scopes of python 25
7 Packages & Modules in Python 27-29
8 Exception Handling in Python 30-32
9 Python Data Structures Overview 33-35
10 Lists, Strings, Sets, Tuples, and Dictionaries in 36-39
Python
11 Files and File Handling in Python 40-41
12 Regular Expressions in Python 42-43
13 CONCLUSION 44

x
CHAPTER 1
INTRODUCTION TO AI

Fig1.0

1.1 What is ARTIFICIAL INTELLIGENCE:


Artificial intelligence (AI) is a set of technologies that enable computers to
perform a variety of advanced functions, including the ability to see,
understand and translate spoken and written language, analyse data,
make recommendations, and more.

AI is the backbone of innovation in modern computing, unlocking value


for individuals and businesses. For example, optical character
recognition (OCR) uses AI to extract text and data from images and
documents, turns unstructured content into business-ready structured
data, and unlocks valuable insights. Artificial intelligence is a field of
science concerned with building computers and machines that can
reason, learn, and act in such a way that would normally require human
intelligence or that involves data whose scale exceeds what humans can
analyse.

1.2 HOW AI WORKS:

Fig1.1

1
1.3 Types of Artificial Intelligence:
Artificial intelligence can be organized in several ways, depending on
stages of development or actions being performed.

For instance, four stages of AI development are commonly recognized.

Reactive machines: Limited AI that only reacts to different kinds of


stimuli based on preprogrammed rules. Does not use memory and thus
cannot learn with new data. IBM’s Deep Blue that beat chess champion
Garry Kasparov in 1997 was an example of a reactive machine.

Limited memory: Most modern AI is considered to be limited memory.


It can use memory to improve over time by being trained with new data,
typically through an artificial neural network or other training model.
Deep learning, a subset of machine learning, is considered limited
memory artificial intelligence time

Theory of mind: Theory of mind AI does not currently exist, but


research is ongoing into its possibilities. It describes AI that can
emulate the human mind and has decision-making capabilities equal
to that of a human, including recognizing and remembering emotions
and reacting in social situations as a human would.

Self-aware: A step above theory of mind AI, self-aware AI describes a


mythical machine that is aware of its own existence and has the
intellectual and emotional capabilities of a human. Like theory of mind
AI, self-aware AI does not currently exist.

Fig 1.2

2
1.4 Artificial Intelligence Training Models:
Supervised learning is a machine learning model that maps a specific
input to an output using labelled training data (structured data).

Unsupervised learning is a machine learning model that learns


patterns based on unlabelled data (unstructured data). Unlike
supervised learning, the end result is not known ahead of time. Rather,
the algorithm learns from the data, categorizing it into groups based on
attributes. For instance, unsupervised learning is good at pattern
matching and descriptive modelling.

In addition to supervised and unsupervised learning, a mixed approach


called semi-supervised learning is often employed, where only some of
the data is labelled. In semi-supervised learning, an end result is
known, but the algorithm must figure out how to organize and structure
the data to achieve the desired results.

Fig 1.3

3
1.5 Benefits of AI:

Fig 1.4
1.6 Applications of AI:

Fig 1.5

4
CHAPTER : 2
What is Data Science
Data Science is a combination of multiple disciplines that uses statistics,
data analysis, and machine learning to analyse data and to extract
knowledge and insights from it.

Data Science is about data gathering, analysis and decision-


making.

Data Science is about finding patterns in data, through analysis, and make
future predictions.

 By using Data Science, companies are able to make:


 Better decisions (should we choose A or B)
 Predictive analysis (what will happen next?)
 Pattern discoveries (find pattern, or maybe hidden information in the
data)

2.1 Where is Data Science Needed:


 For route planning: To discover the best routes to ship
 To foresee delays for flight/ship/train etc. (through predictive
analysis)
 To create promotional offers
 To find the best suited time to deliver goods
 To forecast the next years revenue for a company
 To analyse health benefit of training
 To predict who will win elections

Data Science can be applied in nearly every part of a business where data is
available. Examples are:

 Consumer goods
 Stock markets
 Industry
 Politics
 Logistic companies
 E-commerce

2.2 What is Data:


Data is a collection of information.

5
One purpose of Data Science is to structure data, making it
interpretable and easy to work with.

Data can be categorized into two groups:

 Structured data
 Unstructured data

Fig 2.1
2.3 How Does a Data Scientist Work:
A Data Scientist requires expertise in several backgrounds:

 Machine Learning
 Statistics
 Programming (Python or R)
 Mathematics
 Databases

6
Fig 2.2
1. Problem Statement:

No work starts without motivation, Data science is no exception though.


It’s really important to declare or formulate your problem statement
very clearly and precisely. Your whole model and it’s working depend
on your statement. Many scientists consider this as the main and much
important step of Date Science. So, make sure what’s your problem
statement and how well can it add value to business or any other
organization.

2. Data Collection:

After defining the problem statement, the next obvious step is to go in


search of data that you might require for your model. You must do good
research, find all that you need. Data can be in any form i.e.
unstructured or structured. It might be in various forms like videos,
spreadsheets, coded forms, etc. You must collect all these kinds of
sources.

3. Data Cleaning:

As you have formulated your motive and also you did collect your data,
the next step to do is cleaning. Yes, it is! Data cleaning is the most
favourite thing for data scientists to do. Data cleaning is all about the
removal of missing, redundant, unnecessary and duplicate data from
your collection. There are various tools to do so with the help of
programming in either R or Python. It’s totally on you to choose one of
them. Various scientist has their opinion on which to choose. When it
comes to the statistical part, R is preferred over Python, as it has the
privilege of more than 12,000 packages. While python is used as it is
fast, easily accessible and we can perform the same things as we can in
R with the help of various packages.

4. Data Analysis and Exploration:

7
It’s one of the prime things in data science to do and time to get inner
Holmes out. It’s about analysing the structure of data, finding hidden
patterns in them, studying behaviours, visualizing the effects of one
variable over others and then concluding. We can explore the data with
the help of various graphs formed with the help of libraries using any
programming language. In R, GGplot is one of the most famous models
while Matplotlib in Python.

5. Data Modelling:

Once you are done with your study that you have formed from data
visualization, you must start building a hypothesis model such that it
may yield you a good prediction in future. Here, you must choose a good
algorithm that best fit to your model. There different kinds of algorithms
from regression to classification, SVM (Support vector machines),
Clustering, etc. Your model can be of a Machine Learning algorithm.
You train your model with the train data and then test it with test data.
There are various methods to do so. One of them is the K-fold method
where you split your whole data into two parts, one is Train and the
other is test data. On these bases, you train your model.

6. Optimization and Deployment:

You followed each and every step and hence build a model that you feel
is the best fit. But how can you decide how well your model is
performing? This where optimization comes. You test your data and find
how well it is performing by checking its accuracy. In short, you check
the efficiency of the data model and thus try to optimize it for better
accurate prediction. Deployment deals with the launch of your model
and let the people outside there to benefit from that. You can also obtain
feedback from organizations and people to know their need and then to
work more on your model.

2.4 Applications of Data Science:

Fig 2.3

8
CHAPTER : 3
Machine Learning concepts and Applications
Machine learning (ML) allows computers to learn and make decisions without
being explicitly programmed. It involves feeding data into algorithms to
identify patterns and make predictions on new data. Machine learning is used
in various applications, including image and speech recognition, natural
language processing, and recommender systems.

3.1 Why do we need Machine Learning?


Machine Learning algorithm learns from data, trains on patterns, and
solves or predicts complex problems beyond the scope of traditional
programming. It drives better decision-making and tackles intricate
challenges efficiently.

 Solving Complex Business Problems


 Handling Large Volumes of Data
 Automate Repetitive Tasks
 Personalized User Experience
 Self-Improvement in Performance

3.2 What Makes a Machine “Learn”?


A machine “learns” by recognizing patterns and improving its
performance on a task based on data, without being explicitly
programmed.

The process involves:

Data Input: Machines require data (e.g., text, images, numbers) to


analyse.
Algorithms: Algorithms process the data, finding patterns or
relationships.

Model Training: Machines learn by adjusting their parameters based


on the input data using mathematical models.

Feedback Loop: The machine compares predictions to actual outcomes


and corrects errors (via optimization methods like gradient descent).

Experience and Iteration: Repeating this process with more data


improves the machine’s accuracy over time.

Evaluation and Generalization: The model is tested on unseen data


to ensure it performs well on real-world tasks.

9
3.3 Importance of Data in Machine Learning:
Data is the foundation of machine learning (ML). Without quality data,
ML models cannot learn, perform, or make accurate predictions.

 Data provides the examples from which models learn patterns


and relationships.
 High-quality and diverse data improves model accuracy and
generalization.
 Data ensures models understand real-world scenarios and adapt
to practical applications.
 Features derived from data are critical for training models.
 Separate datasets for validation and testing assess how well the
model performs on unseen data.
 Data fuels iterative improvements in ML models through
feedback loops.

Fig 3.0

3.5 Challenges of Machine Learning:

Fig 3.1

10
CHAPTER : 4
PYTHON
Python is a programming language widely used by Data Scientists.

Python has in-built mathematical libraries and functions, making it easier to


calculate mathematical problems and to perform data analysis.

4.1 Why Python for Data Science?


Python is favoured in data science due to its readability, simplicity, and
versatility. Its extensive libraries and frameworks streamline complex
tasks, allowing data scientists to focus on problem-solving rather than
coding intricacies.

Fig 4.1

4.2 Features of Python:

Fig 4.2

11
4.3 Key Libraries and Tools:
NumPy: A fundamental library for numerical operations in Python,
supporting large, multi-dimensional arrays and matrices.

pandas: A powerful library for data manipulation and analysis, offering


data structures like Data Frames to handle structured data efficiently.

Scikit-learn: A comprehensive library for machine learning, providing


simple and efficient data mining and analysis tools.

Matplotlib and Seaborn: Libraries for creating static, animated, and


interactive visualizations, helping to understand data patterns and
trends

Fig 4.3

4.4 Advantages and Disadvantages of Python:

Fig 4.4

12
4.5 Applications of Python:

Fig 4.5

Benefits of Python:

Fig 4.6

4.6 Difference between Python and R Language

Fig 4.7

13
CHAPTER: 5
Python Syntax, Data Types & Operators
Python is known for its clean and readable syntax, which makes it an
excellent language for beginners and professionals working in AI, data
science, and software development.

5.1 Python Syntax


Python syntax refers to the set of rules that define how a Python program is
written and interpreted. One of the most distinctive and beginner-friendly
aspects of Python is its clean and readable syntax. Unlike many other
programming languages that use curly braces {} to define code blocks, Python
uses indentation (whitespace). This means that consistent indentation is not
just a style, but a requirement in Python—usually 4 spaces are used per
indentation level.

A Python program is made up of statements and expressions. Statements are


instructions (like if, for, or def) that perform actions, while expressions are
combinations of values and operators that evaluate to a result. Python is case-
sensitive, so Name, name, and NAME are all treated as different identifiers.

Some key points of Python syntax:

Comments start with # and are ignored by the interpreter. Use them to explain
your code.
Variables do not require a type declaration; the type is inferred from the value
(e.g., x = 10).

Functions are defined using the def keyword, and blocks of code are
structured using colons (:) followed by indented lines.

Control structures like if, elif, else, for, and while are written in a natural,
readable way.

Importing modules is done using the import keyword.

Example:

# This is a comment

def greet(name):

if name:

print (f"Hello, {name}!")

else:

14
print ("Hello, Guest!")

greet("Alice")

Python also supports a REPL (Read-Eval-Print Loop) mode, where you can
type Python code line by line and see immediate results. This makes it great
for quick testing and learning. Overall, Python's syntax emphasizes
readability, simplicity, and consistency, which is why it's so widely loved by
beginners and professionals alike.

Fig 5.1

5.2 Python Data Types:


In Python, data types define the kind of value a variable can hold, and they
are essential for writing correct and efficient programs. Python is a
dynamically typed language, which means you don't need to declare the data
type of a variable explicitly—Python detects it automatically at runtime. The
built-in data types in Python can be broadly categorized into several types:

15
◆ 1. Numeric Types

These include:

int – for integers (e.g., 10, -5)

float – for decimal numbers (e.g., 3.14, -0.01)

complex – for complex numbers (e.g., 2 + 3j)

◆ 2. Sequence Types

These are ordered collections:

str – string, a sequence of characters (e.g., "Hello")

list – mutable sequence of items (e.g., [1, 2, 3])

tuple – immutable sequence (e.g., (4, 5, 6))

◆ 3. Set Types

set – unordered collection of unique items (e.g., {1, 2, 3})

frozen set – like a set but immutable

◆ 4. Mapping Type

dict – a collection of key-value pairs (e.g., {"name": "Alice", "age": 25})

◆ 5. Boolean Type

bool – represents True or False, typically used in conditional expressions

◆ 6. Binary Types

Used to handle binary data:

bytes – immutable sequence of bytes

bytearray – mutable sequence of bytes

memoryview – memory-efficient view of bytes

16
◆ 7. None Type

NoneType – represents the absence of a value, written as None

Example:

a = 10 # int

b = 3.14 # float

c = "Python" # str

d = [1, 2, 3] # list

e = {"key": 1} # dict

f = True # bool

Python also allows you to check the type of a variable using the built-in type()
function, and you can convert between types using type casting, such as int(),
float(), str(), etc. Understanding data types is foundational for writing correct
Python code, as operations and functions behave differently depending on the
type of data they work with.

5.3 Operators:
In Python, operators are special symbols or keywords used to perform
operations on variables and values. Python supports several types of
operators that enable arithmetic operations, comparisons, logical decisions,
bitwise manipulations, and more. These operators make it easier to write
expressions that carry out calculations and control flow in programs.

1. Arithmetic Operators

Used to perform basic mathematical operations:

+ (Addition), - (Subtraction), * (Multiplication), / (Division)

// (Floor Division), % (Modulus), ** (Exponentiation)

Example:

a=5

b=2

print (a + b) # 7

print (a ** b) # 25

2. Comparison (Relational) Operators

17
Used to compare values and return a boolean result:

== (Equal to),!= (Not equal to)

> (Greater than), < (Less than)

>= (Greater than or equal to), <= (Less than or equal to)

Example:

x = 10

y = 20

print (x < y) # True

3. Logical Operators

Used to combine conditional statements:

and – True if both conditions are true

or – True if at least one condition is true

not – Reverses the result (True becomes False)

Example:

a=5

print (a > 2 and a < 10) # True

4. Assignment Operators

Used to assign values to variables:

=, +=, -=, *=, /=, %=, **=, //=

Example:

x=5

x += 3 # x becomes 8

5. Bitwise Operators

Used to perform operations on binary representations:

& (AND), | (OR), ^ (XOR)

~ (NOT), << (Left Shift), >> (Right Shift)

18
Example:

a=5 # 0101

b=3 # 0011

print (a & b) # 1 (0001)

6. Membership Operators

Used to test if a value is a member of a sequence (like list, string, tuple):

in – returns True if value exists

not in – returns True if value does not exist

Example:

fruits = ["apple", "banana"]

print ("apple" in fruits) # True

7. Identity Operators

Used to compare memory locations of objects:

is – returns True if two variables point to the same object

is not – returns True if they do not

Example:

x = [1, 2, 3]

y=x

print (x is y) # True

5.4 Control Statements:


Control statements in Python are used to manage the flow of execution in a
program. They allow you to make decisions, repeat actions, or jump out of
certain code blocks based on conditions. The three main types of control
statements are conditional statements, looping statements, and loop control
statements.

◆ Conditional Statements
These statements let your program make decisions based on certain
conditions. Python uses:

19
if – executes a block if the condition is true

elif – checks another condition if the previous one was false

else – executes a block if all previous conditions were false

Example:

x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

◆ Looping Statements
Loops are used to repeat a block of code multiple times.

for loop – iterates over a sequence (like a list, string, or range)

while loop – repeats as long as a condition is true

Examples:

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

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

◆ Loop Control Statements


These are used to alter the flow inside loops:

break – exits the loop immediately

continue – skips the rest of the current iteration

20
pass – does nothing, used as a placeholder

Example:

for i in range (5):


if i == 3:
break
print(i) # prints 0, 1, 2

for i in range (5):


if i == 3:
continue
print(i) # prints 0, 1, 2, 4
Control statements are the backbone of decision-making and repetition in
Python, making it possible to write intelligent, responsive, and efficient
programs.

5.4 Strings in Python:


Strings in Python

In Python, a string is a sequence of characters used to represent textual data


such as words, sentences, or even numbers written as text. Strings are
enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """) for
multi-line strings. Python strings are immutable, meaning once a string is
created, its characters cannot be changed individually—you can only create a
new string through operations. Strings support a variety of operations like
concatenation, slicing, and iteration, and are widely used in almost every
Python program.

Python offers many powerful string methods to work with text, such as:

upper () – converts to uppercase

lower () – converts to lowercase

title () – capitalizes each word

21
strip () – removes whitespace from both ends

replace (old, new) – replaces parts of the string

split () – splits the string into a list

join () – joins elements of a list into a single string

find () – returns the index of the first match

startswith () / endswith () – checks how a string begins or ends

Example:

text = “Python is awesome! “

print(text.strip().upper()) # Output: PYTHON IS AWESOME!

Strings can also be indexed and sliced:

word = "Python"

print(word[0]) # P (first character)

print(word[-1]) # n (last character)

print (word [1:4]) # yth (slicing from index 1 to 3)

Python also supports string formatting, which allows you to embed variables
into strings:

Using f-strings: f"Hello, {name}!"

Using .format(): "Hello, {}”. format(name)

Using % formatting (older style): "Hello, %s" % name

A string is a sequence of characters which is enclosed in quotes.

22
There are basically 3 types of operators supported by string:

 Basic Operators: There are two types of basic operators in string. They are
“+” and “*”.
1. Concatenation Operator (+): the concatenation operator concatenates
two strings and forms a new string.
2. Replication Operator (*): It is used to repeat a string number of times
the string will be repeated the number of times is given by the integer
value.
 Membership operators: To test whether a value is present in a sequence.
 Relational Operators: All the comparisons operators i.e., (<,>, <=,>=, == ,!=,
<>)
 Slice Notation: String Slice can be defined as substring which is the part of
string. Therefore, further substring can be obtained from a string.

Strings in Python are versatile and essential, used in everything from simple
output messages to file handling, data parsing, and user input. Their
flexibility and the wide range of methods make them one of the most
important data types in Python.

23
CHAPTER:6
Functions and Scope in Python
In Python: functions, modules, and exception handling. These concepts help
developers write organized, reusable, and error-free code, making Python a
powerful and efficient programming language for AI, data science, and
software development.

6.1 Functions in Python:


Functions in Python

In Python, a function is a reusable block of code that performs a specific task.


Functions help organize code, make it more readable, reduce repetition, and
allow for modular programming. You can define a function using the def
keyword, followed by the function name and parentheses (), which may
include parameters—placeholders for the inputs the function can receive. The
code inside the function is indented and runs only when the function is called.
If a function should return a result, you use the return statement. In

• Built-in Functions such as print (), len (), and range ().

• User-defined Functions, where programmers create their own functions


using the def

keyword.

• Function Parameters and Return Values, enabling functions to accept


input and return

output for better flexibility.

• Lambda Functions, which are small anonymous functions used for quick,
short operations.

Example:

def greet(name):

return f"Hello, {name}!"

print(greet("Alice")) # Output: Hello, Alice!

Python also supports default arguments, where parameters can have default
values:

24
python

Copy

Edit

def greet(name="Guest"):

print (f"Welcome, {name}!")

Functions can take any number of arguments using:

*args for variable-length positional arguments

**kwargs for variable-length keyword arguments

Python also allows anonymous functions using the lambda keyword. These
are short, one-line functions used for simple tasks, especially with functions
like map (), filter (), and sorted ().

Example:

square = lambda x: x * x

print (square (5)) # Output: 25

6.2 Scopes of Python


In Python, scope refers to the visibility and accessibility of variables
within different parts of a program. Scope determines where a variable
is accessible and where not. In order to understand how variables
behave within functions and how they interact with each other, it is
crucial to understand scope.

Python has two main types of scope:

Local scope:
 Variables declared within a function have local scope. They are
accessible only within the function in which they are defined.
 Local variables are created when the function is called and
destroyed when it exits.
 Local variables cannot be accessed from outside the function.

25
Global Scope:
 Variables declared outside of any function or at the top level of a
script have global scope. They are accessible throughout the
program.
 During program startup, global variables are created in memory
and remain there until the program ends.
 Global variables can be accessed from any function within the
program.

Nested scope:
 Python allows nested functions, where one function is defined
inside another.
 During nested functions, the inner function has access to
variables in the outer (enclosed) function.
 The inner function's scope is called "nested scope" because it
includes both its local scope and the enclosing function's scope.

26
CHAPTER: 7
Packages and Modules in Python
Introduction
Python is a high-level, general-purpose programming language widely used in
various domains including data science, machine learning, web development,
and automation. One of Python’s key strengths is its modular structure,
which allows developers to organize code into reusable components. This
modularity is achieved through the use of modules and packages, which play
a vital role in organizing, maintaining, and scaling Python projects effectively.

Modules in Python
A module is a file containing Python code that is written for reuse. It typically
consists of functions, classes, and variables that serve specific functionalities.
The primary goal of a module is to break down large programs into smaller,
manageable, and logically organized parts. This enhances code readability,
promotes reuse, and simplifies debugging and maintenance.

Modules form the foundational building blocks of Python programs. They can
be standard (built-in to Python), third-party (installed externally), or user-
defined (created by the developer). Using modules also allows for separation
of concerns, where each module is responsible for a specific part of the
program logic, reducing complexity in large codebases.

27
Packages in Python
A package is a hierarchical file structure that contains multiple modules
grouped together to form a collection of related functionalities. Packages allow
developers to organize their modules into directories, thereby creating a
scalable project structure. The presence of a special initialization file in the
directory indicates to Python that it should treat the directory as a package.

Packages are essential when working on large projects that involve multiple
components. By categorizing similar modules into packages, developers can
avoid naming conflicts, improve code organization, and enable better
navigation through the codebase. Packages can also contain sub-packages,
allowing for multi-level structuring of code.

Advantages of Using Modules and Packages

The use of modules and packages provides several benefits in software


development:

 Reusability: Code can be written once and reused in different


programs.

 Maintainability: Issues can be isolated and fixed within individual


modules or packages.

 Readability: Well-structured code is easier to understand and modify.

 Namespace Management: Helps avoid conflicts by isolating function


and variable names.

 Scalability: Supports growth of codebase in an organized manner,


especially in large projects.

In professional environments, especially in domains like data science,


modular programming with well-organized packages and modules is
considered a best practice.

Relevance in Data Science


In the field of data science, modular code organization is crucial due to the
multifaceted nature of tasks such as data preprocessing, analysis,
visualization, and model evaluation. Data scientists frequently work with
various Python packages designed for specific tasks. Understanding the
structure and use of modules and packages enables data scientists to build
efficient, reusable, and well-organized code pipelines.

During the course of my internship in the domain of data science, I learned


the importance of modular programming when dealing with data workflows.
The use of packages and modules made it easier to manage code, automate

28
repetitive processes, and collaborate effectively in a team environment. This
approach not only improved the quality of the code but also enhanced overall
productivity.
Modules in Python are essential components that allow programmers to
organize code into separate files and reuse functionality across different
programs. A module is simply a file containing Python code—such as
functions, classes, or variables—that can be imported and used in another
Python script. Python supports various types of modules, including built-in
modules like math, os, and datetime, which come pre-installed and provide
powerful features for mathematical operations, file handling, and date/time
manipulation. Users can also create their own custom modules, known as
user-defined modules, to structure their code better and enhance reusability.
Additionally, third-party modules like numpy, pandas, matplotlib, and flask
can be installed using Python’s package manager pip to perform specific tasks
such as data analysis, visualization, and web development. Modules can be
imported using the import statement, and specific functions or classes can be
brought in using from module import name. By using modules, Python
promotes modular programming, which leads to cleaner, more manageable
code, encourages reusability, reduces redundancy, and improves overall
program structure. Whether for small scripts or large applications, modules
play a vital role in efficient and effective Python development.

29
CHAPTER: 8
EXCEPTION HANDLING IN PYTHON
Introduction
In any programming language, errors are a natural part of the development
process. Python provides a structured way to detect and handle these errors
using a mechanism called exception handling. This allows programs to
respond to unexpected situations without crashing, thereby improving
robustness, user experience, and overall software reliability.

Exception handling is a critical concept in Python, particularly in data-driven


applications where unpredictable user input, file errors, or network issues
can arise. Effective handling of exceptions ensures smooth execution and
helps in debugging, logging, and maintaining code efficiently.

Understanding Exceptions
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions are not necessarily errors
in logic; they often result from conditions that are beyond the control of the
program, such as attempting to access a file that does not exist or dividing a
number by zero.

In Python, exceptions are objects that represent these error conditions. When
an exception occurs, Python immediately stops the current flow of the
program and looks for a way to handle the exception. If not handled, the
program terminates and displays an error message, commonly referred to as
a traceback.

Exception Handling Mechanism


Python uses a structured approach to manage exceptions through specific
keywords that help detect and respond to exceptions. The handling
mechanism allows developers to define blocks of code to try and detect errors,
and to define alternative behaviours in case an error occurs. This approach
separates normal program logic from error handling, which leads to clearer
and more maintainable code.

The exception handling structure in Python includes the following:

 A block to attempt execution.

 One or more blocks to handle specific or general exceptions.

 An optional block that executes regardless of whether an exception


occurred.

30
 An optional block for cleanup actions.

This mechanism provides flexibility and control over how different types of
exceptions are managed and ensures that the program can continue running
or exit gracefully.

Benefits of Exception Handling


Proper use of exception handling brings multiple benefits to Python programs,
especially in complex or user-facing applications. Some key advantages
include:

 Error Isolation: Helps identify exactly where the error occurred without
affecting the rest of the code.

 Improved User Experience: Allows for graceful failure and user-friendly


error messages instead of program crashes.

 Code Clarity: Separates normal program logic from error handling,


making code cleaner and easier to understand.

 System Stability: Prevents unexpected terminations by managing rare


or unanticipated situations safely.

 Maintenance & Debugging: Makes the program easier to maintain and


debug by providing detailed error messages and control flow.

Exception Hierarchy and Custom Exceptions


Python’s built-in exception classes are arranged in a hierarchy, starting from
a base class. This structure allows developers to catch a broad category of
errors or target specific ones. Additionally, Python allows developers to define
their own custom exceptions by creating new classes. This is especially useful
in larger projects, including data science applications, where domain-specific
errors need to be clearly identified and handled.

Custom exception handling improves code readability and gives a clearer


understanding of how certain errors are treated uniquely, contributing to
better error tracking and documentation.

Relevance in Data Science


In the domain of data science, exception handling is crucial due to the
unpredictability of data sources and system resources. Whether it is reading
from external files, processing real-time data, or interacting with APIs,
exceptions can occur at multiple stages. Proper handling ensures that data
pipelines do not break due to a single failure and that logs are maintained for
future analysis.

31
During my internship in the field of data science, I encountered several
scenarios where exception handling became necessary—for instance, when
handling missing values, managing file loading issues, or connecting to
external databases. Implementing structured exception handling helped me
build resilient scripts that could run reliably in different environments with
varying data inputs.

Conclusion
Exception handling is a fundamental aspect of writing robust and
professional-grade Python applications. It allows developers to anticipate and
manage errors effectively, ensuring that programs behave predictably even
under unexpected conditions. In data science and other real-world
applications, the ability to handle exceptions gracefully not only improves
performance but also enhances the reliability and trustworthiness of the
system. My internship experience underscored the importance of mastering
exception handling to create stable, scalable, and user-friendly Python
solutions.

32
CHAPTER: 9
PYTHON DATA STRCTURES
Introduction
Data structures are the foundational building blocks of any programming
language. In Python, data structures are used to store, organize, and manage
data efficiently. They provide a means of performing operations on data and
are essential for solving complex computational problems. Python offers a rich
collection of built-in data structures that are both flexible and easy to use,
which makes the language especially powerful for data science and software
development.

Understanding and utilizing Python’s data structures effectively is crucial for


writing optimized and maintainable code. They support efficient data
manipulation, enable clear program logic, and allow for better performance
across a wide range of applications.

Types of Data Structures in Python


Python provides several built-in data structures, each with unique properties,
performance characteristics, and use cases. These can be categorized into two
main types: primitive and non-primitive data structures.

1. Primitive Data Structures

These are the most basic data types in Python, including:

 Integers

 Floats

 Strings

 Booleans
While not considered data structures in the traditional sense, these primitives
form the basis for more complex types.

2. Non-Primitive Data Structures

These include more advanced structures that are capable of storing multiple
elements and performing operations on them. The primary non-primitive data
structures in Python are:

 Lists: Ordered and mutable collections of elements.

 Tuples: Ordered but immutable sequences.

 Sets: Unordered collections of unique elements.

33
 Dictionaries: Key-value pairs for efficient lookup and storage.

Each of these structures is implemented in a way that allows for dynamic


memory management, and they can grow or shrink as needed, which makes
them more flexible than traditional arrays in other languages.

Importance in Programming and Data Science


Efficient use of data structures is essential for solving real-world problems.
They help in organizing data logically and performing operations such as
insertion, deletion, traversal, and searching in a time-efficient manner.
In the context of data science, choosing the right data structure can greatly
impact the performance and scalability of data pipelines and analytical
models. For example, dictionaries are often used for mapping categorical
variables, while lists and tuples are commonly used for storing data records
or feature sets.

Python’s built-in data structures are often used in combination with third-
party libraries like pandas, which extends their functionality for handling
structured data such as tables and time series.

Key Features of Python Data Structures


 Dynamic Typing: Python data structures can hold mixed data types,
adding flexibility during implementation.

 Memory Efficiency: Python manages memory dynamically, which


simplifies development while still allowing efficient performance.

 Ease of Use: The syntax and operations associated with Python’s data
structures are intuitive and user-friendly.

 Rich Functionality: Python provides a wide range of built-in methods


for manipulating data structures, enhancing productivity and code
readability.

 Extensibility: Built-in structures can be extended or customized to


create more complex structures such as stacks, queues, and graphs
using object-oriented programming.

Applications in Real-World Projects


During the course of my internship in data science, I worked with large and
complex datasets requiring structured organization and efficient data
manipulation. Python data structures played a key role in managing this data
effectively.

34
Tasks such as data cleaning, transformation, and aggregation were greatly
facilitated by using dictionaries, lists, and sets. Understanding the underlying
structure of data allowed me to implement faster and more reliable solutions,
especially when dealing with large-scale operations or real-time data.

Data structures also supported integration with various tools and libraries,
enabling seamless development of end-to-end data workflows.

35
Chapter:10
Lists, Tuples, Sets, Dictionaries and Strings in
Python
List
A list in Python is a dynamic, ordered collection that can store elements of
different data types such as integers, floats, strings, or even other lists (nested
lists). Lists are mutable, so you can change, add, or delete elements without
creating a new list. They are defined using square brackets []. Lists are
versatile and widely used for storing a sequence of items such as a list of
student names, shopping items, or daily temperatures.

Common methods include:

 append () – adds an item to the end

 insert () – inserts an item at a specific index

 pop () – removes and returns the last element

 sort () – sorts the list in ascending order

 reverse () – reverses the list

Example:

fruits = ["apple", "banana", "cherry"]


fruits. Append("orange")

print(fruits)

Output = ['apple', 'banana', 'cherry', 'orange']

String
A string is a sequence of Unicode characters used to represent text. Strings
are immutable, meaning once created, their content cannot be changed. You
can perform various operations on strings like slicing, searching, formatting,
and joining. Strings are defined using single ' or double " quotes, and multiline
strings use triple quotes ''' or """.

Common methods include:

 upper () – converts to uppercase

 lower () – converts to lowercase

 find () – finds a substring

36
 replace () – replaces part of the string

 split () – splits the string into a list

Example:

python

message = "Python is fun"

print (message. Upper ())

Output = PYTHON IS FUN

Tuple
A tuple is a collection similar to a list but immutable, meaning once it's
created, you cannot add, remove, or change elements. Tuples are defined
using parentheses (). Because they are immutable, they can be used as
dictionary keys or elements in a set, which lists cannot do. Tuples are
usually used when the data should not be changed throughout the program,
like coordinates (x, y) or months of the year.

Common operations:

 Accessing elements via index

 Iterating with loops

 Using count () and index () methods

Example:

python

dimensions = (10, 20, 30)

print (dimensions [1])

Output = 20

Advantages:

 Faster than lists (since immutable)

 Safer for storing fixed data

Dictionary
A dictionary is an unordered, mutable collection of key-value pairs. Each
key must be unique and immutable (like strings, numbers, or tuples).
Dictionaries are written using curly braces {}. They are commonly used to
store data like student records, configurations, or any structured data.

37
Common methods:

 get () – safely gets a value by key

 keys () – returns all keys

 values () – returns all values

 items () – returns all key-value pairs

 update () – updates the dictionary with another dictionary

Example:

python

student = {"name": "Alice", "age": 20, "grade": "A"}

print(student["name"])

Output = Alice

Use Cases:

 Storing structured data (e.g., JSON-like)

 Fast lookups based on keys

 Grouping related values together

Set
A set is a collection of unordered, unique items. Sets are useful when you
want to ensure there are no duplicate entries. Sets are mutable, meaning you
can add or remove elements, but they do not support indexing or slicing
because they are unordered. Sets are ideal for operations like union,
intersection, and difference between groups.

Common methods:

 add () – adds an element

 remove () – removes an element

 union () – combines two sets

 intersection () – finds common elements

 difference () – elements in one set but not another

Example:

python

set1 = {1, 2, 3}

38
set2 = {3, 4, 5}

print (set1 & set2)

Output = {3}

39
Chapter: 11
Files and File Handling in Python
Files and File Handling in Python
In Python, file handling allows you to create, read, write, and delete files
directly from your Python program. This is especially useful when you want
to store data permanently, process text files, or interact with external files like
logs, reports, or configurations. Python provides built-in functions for file
handling, and the most common one is the open () function. This function is
used to open a file and returns a file object, which lets you perform various
operations on the file.

When opening a file, you must specify the mode:

 "r" – Read (default mode; file must exist)

 "w" – Write (creates a new file or overwrites if it exists)

 "a" – Append (adds data to the end of the file)

 "x" – Create (creates a file, returns error if file exists)

 Add "b" for binary mode (e.g., "rb" for read binary)

 Add "+" to read and write ("r+", "w+", etc.)

To read data from a file, you can use:

 read () – reads the entire file as a string

 readline () – reads one line at a time

 readlines () – reads all lines and returns a list

To write to a file, use write () or writelines (). After you're done working with a
file, it’s important to close it using close () to free up system resources.
However, the better way to handle files in Python is using a with block (also
called a context manager), which automatically closes the file when done.
Example (writing and reading a file):

python

# Writing to a file

with open ("example.txt", "w") as file:

file.write ("Hello, this is a test file.\n")

file.write("Python is fun!")

40
# Reading from a file

with open ("example.txt", "r") as file:

content = file.read()

print(content)

Advantages of Python's file handling include simplicity, cross-platform


compatibility, and powerful tools for both text and binary file operations. It is
widely used in data processing, saving logs, creating reports, and handling
user inputs.

41
Chapter: 12
Regular Expressions in Python
Regular Expressions (commonly abbreviated as RegEx) are powerful tools
used in Python to search, match, and manipulate strings based on specific
patterns. They are especially useful when you need to validate input (like
emails or phone numbers), extract specific parts of text, or perform complex
text replacements. Python provides the re module for working with regular
expressions. To use it, you must import it with import re.

At the core of regular expressions are patterns made up of special


characters. Some common ones include:

 . – matches any character except newline

 ^ – matches the start of a string

 $ – matches the end of a string

 * – matches 0 or more repetitions

 + – matches 1 or more repetitions

 ? – matches 0 or 1 repetition

 [] – matches any one character inside the brackets

 \d – matches any digit (0-9)

 \w – matches any alphanumeric character

 \s – matches any whitespace character

Common functions in the re module:


 re.match () – checks for a match only at the beginning of a string

 re.search() – searches the whole string for the first match

 re.findall() – returns all non-overlapping matches as a list

 re.sub() – replaces matched patterns with a new string

 re.compile() – compiles a regular expression pattern for reuse

Example:

python

import re

42
text = "My phone number is 9876543210"

pattern = r"\d {10}” # matches exactly 10 digits

match = re.search(pattern, text)

if match:

print ("Phone number found:", match. group ()) # Output: 9876543210

Regular expressions can be tricky at first, but they are incredibly powerful
once mastered. You can build anything from simple string filters to complex
parsers. Python also allows the use of flags like re.IGNORECASE or
re.MULTILINE to control how matching is done.

43
CHAPTER : 13
CONCLUSION
Data Science stands at the forefront of the digital revolution, playing a pivotal
role in transforming raw data into meaningful insights that drive strategic
decisions. It is a multidisciplinary field that blends mathematics, statistics,
programming, and domain knowledge to solve real-world problems. From
healthcare and finance to agriculture and entertainment, data science is being
used to optimize operations, predict future trends, personalize user
experiences, and automate tasks through artificial intelligence and machine
learning.

As the volume of data generated continues to grow at an unprecedented rate,


the demand for skilled data scientists is also increasing rapidly. Tools like
Python, R, SQL, and big data technologies such as Hadoop and Spark have
become essential in managing and analyzing vast datasets efficiently.
Moreover, advancements in deep learning and natural language processing
have opened up new possibilities, enabling machines to understand human
language, recognize images, and even make autonomous decisions.

However, with great power comes great responsibility. It is crucial to address


challenges related to data privacy, security, bias, and ethical use. Data
scientists must not only focus on technical accuracy but also consider the
societal implications of their work.

In conclusion, data science is more than just a technical field—it is a catalyst


for innovation and a bridge between data and meaningful action. As
technology evolves, those equipped with strong analytical skills, curiosity, and
ethical awareness will be at the forefront of shaping a smarter, more data-
driven world.

44
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have
supported and guided me throughout my Python Course internship. My
heartfelt thanks to Skill Dzire Organization for providing me with the
opportunity to work and enhance my skills in the field of Python course. I am
deeply thankful to Visakha Institute of Engineering & Technology (VIET)
for offering a supportive environment that made this experience possible. I
extend my sincere appreciation to Dr. G. Satyanarayana, Chairman of VIET,
for his visionary leadership, and Dr. G.V. Pradeep Varma, Principal of VIET,
for his continuous encouragement. I would also like to thank Dr. D. Santha
Rao, Dean of Academics, for his insightful guidance, and Dr. P. Varma,
Training and Placement Officer (TPO), for his efforts in facilitating this
internship. My thanks are also due to Dr. B. Jeevana Rao, Head of the
Department of Electronics and Communication Engineering (ECE), for his
academic support. I am especially grateful to my Project Guide, Mrs. K.
KANTHI KINNERA M. tech, (Ph . D), for her valuable mentorship, constant
encouragement, and expert guidance throughout the internship. Additionally,
I would like to acknowledge the faculty members of the ECE department
whose teachings and support have played a crucial role in my academic
development.

vii
ABSTRACT
Data science encompasses a set of principles, problem definitions, algorithms,
and processes for extracting nonobvious and useful patterns from large data
sets. Many of the elements of data science have been developed in related
fields such as machine learning and data mining. In fact, the terms data
science, machine learning, and data mining are often used interchangeably.
The commonality across these disciplines is a focus on improving decision
making through the analysis of data. However, although data science borrows
from these other fields, it is broader in scope. Machine learning (ML) focuses
on the design and evaluation of algorithms for extracting patterns from data.
Data mining generally deals with the analysis of structured data and often
implies an emphasis on commercial applications. Data science takes all of
these considerations into account but also takes up other challenges, such as
the capturing, cleaning, and transforming of unstructured social media and
web data; the use of big-data technologies to store and process big,
unstructured data sets; and questions related to data ethics and regulation.

viii
CONTENTS
S.NO Name of the Topic/Chapter Page No. From
To

1 Introduction to Artificial Intelligence 1-4


What is AI 1
How AI Works 1
Types of AI 2
Training models of AI 3
Benefits of AI 4
Applications of AI 4
2 Introduction to Data Science 5-8
What is Data Science 5
Where Data Science Needed 5
What is Data, Types of Data 6
How Does a Data Scientist Work 8
Applications Of Data science 8
3 Machine Learning Concepts and Applications 9-10
Why do we need Machine Learning 9
What Makes a Machine learn 9
Benefits of Machine Learning 10
Challenges of Machine Learning 10
4 Introduction to Python for AI & Data Science 11-12
Why python for data science 11
Python Important Features & Interfaces 11
Advantages and disadvantages of python 12
Difference between Python and R Language 12
5 Python Basics and Syntax, Operators & Control 13-23
Statements
Syntax of Python 14
Data Types & Special Characters 15

ix
Operators 17
Strings in Python 19
6 Functions and Scope in Python 24-26
Functions of Python 24
Scopes of python 25
7 Packages & Modules in Python 27-29
8 Exception Handling in Python 30-32
9 Python Data Structures Overview 33-35
10 Lists, Strings, Sets, Tuples, and Dictionaries in 36-39
Python
11 Files and File Handling in Python 40-41
12 Regular Expressions in Python 42-43
13 CONCLUSION 44

x
CHAPTER 1
INTRODUCTION TO AI

Fig1.0

1.1 What is ARTIFICIAL INTELLIGENCE:


Artificial intelligence (AI) is a set of technologies that enable computers to
perform a variety of advanced functions, including the ability to see,
understand and translate spoken and written language, analyse data,
make recommendations, and more.

AI is the backbone of innovation in modern computing, unlocking value


for individuals and businesses. For example, optical character
recognition (OCR) uses AI to extract text and data from images and
documents, turns unstructured content into business-ready structured
data, and unlocks valuable insights. Artificial intelligence is a field of
science concerned with building computers and machines that can
reason, learn, and act in such a way that would normally require human
intelligence or that involves data whose scale exceeds what humans can
analyse.

1.2 HOW AI WORKS:

Fig1.1

1
1.3 Types of Artificial Intelligence:
Artificial intelligence can be organized in several ways, depending on
stages of development or actions being performed.

For instance, four stages of AI development are commonly recognized.

Reactive machines: Limited AI that only reacts to different kinds of


stimuli based on preprogrammed rules. Does not use memory and thus
cannot learn with new data. IBM’s Deep Blue that beat chess champion
Garry Kasparov in 1997 was an example of a reactive machine.

Limited memory: Most modern AI is considered to be limited memory.


It can use memory to improve over time by being trained with new data,
typically through an artificial neural network or other training model.
Deep learning, a subset of machine learning, is considered limited
memory artificial intelligence time

Theory of mind: Theory of mind AI does not currently exist, but


research is ongoing into its possibilities. It describes AI that can
emulate the human mind and has decision-making capabilities equal
to that of a human, including recognizing and remembering emotions
and reacting in social situations as a human would.

Self-aware: A step above theory of mind AI, self-aware AI describes a


mythical machine that is aware of its own existence and has the
intellectual and emotional capabilities of a human. Like theory of mind
AI, self-aware AI does not currently exist.

Fig 1.2

2
1.4 Artificial Intelligence Training Models:
Supervised learning is a machine learning model that maps a specific
input to an output using labelled training data (structured data).

Unsupervised learning is a machine learning model that learns


patterns based on unlabelled data (unstructured data). Unlike
supervised learning, the end result is not known ahead of time. Rather,
the algorithm learns from the data, categorizing it into groups based on
attributes. For instance, unsupervised learning is good at pattern
matching and descriptive modelling.

In addition to supervised and unsupervised learning, a mixed approach


called semi-supervised learning is often employed, where only some of
the data is labelled. In semi-supervised learning, an end result is
known, but the algorithm must figure out how to organize and structure
the data to achieve the desired results.

Fig 1.3

3
1.5 Benefits of AI:

Fig 1.4
1.6 Applications of AI:

Fig 1.5

4
CHAPTER : 2
What is Data Science
Data Science is a combination of multiple disciplines that uses statistics,
data analysis, and machine learning to analyse data and to extract
knowledge and insights from it.

Data Science is about data gathering, analysis and decision-


making.

Data Science is about finding patterns in data, through analysis, and make
future predictions.

 By using Data Science, companies are able to make:


 Better decisions (should we choose A or B)
 Predictive analysis (what will happen next?)
 Pattern discoveries (find pattern, or maybe hidden information in the
data)

2.1 Where is Data Science Needed:


 For route planning: To discover the best routes to ship
 To foresee delays for flight/ship/train etc. (through predictive
analysis)
 To create promotional offers
 To find the best suited time to deliver goods
 To forecast the next years revenue for a company
 To analyse health benefit of training
 To predict who will win elections

Data Science can be applied in nearly every part of a business where data is
available. Examples are:

 Consumer goods
 Stock markets
 Industry
 Politics
 Logistic companies
 E-commerce

2.2 What is Data:


Data is a collection of information.

5
One purpose of Data Science is to structure data, making it
interpretable and easy to work with.

Data can be categorized into two groups:

 Structured data
 Unstructured data

Fig 2.1
2.3 How Does a Data Scientist Work:
A Data Scientist requires expertise in several backgrounds:

 Machine Learning
 Statistics
 Programming (Python or R)
 Mathematics
 Databases

6
Fig 2.2
1. Problem Statement:

No work starts without motivation, Data science is no exception though.


It’s really important to declare or formulate your problem statement
very clearly and precisely. Your whole model and it’s working depend
on your statement. Many scientists consider this as the main and much
important step of Date Science. So, make sure what’s your problem
statement and how well can it add value to business or any other
organization.

2. Data Collection:

After defining the problem statement, the next obvious step is to go in


search of data that you might require for your model. You must do good
research, find all that you need. Data can be in any form i.e.
unstructured or structured. It might be in various forms like videos,
spreadsheets, coded forms, etc. You must collect all these kinds of
sources.

3. Data Cleaning:

As you have formulated your motive and also you did collect your data,
the next step to do is cleaning. Yes, it is! Data cleaning is the most
favourite thing for data scientists to do. Data cleaning is all about the
removal of missing, redundant, unnecessary and duplicate data from
your collection. There are various tools to do so with the help of
programming in either R or Python. It’s totally on you to choose one of
them. Various scientist has their opinion on which to choose. When it
comes to the statistical part, R is preferred over Python, as it has the
privilege of more than 12,000 packages. While python is used as it is
fast, easily accessible and we can perform the same things as we can in
R with the help of various packages.

4. Data Analysis and Exploration:

7
It’s one of the prime things in data science to do and time to get inner
Holmes out. It’s about analysing the structure of data, finding hidden
patterns in them, studying behaviours, visualizing the effects of one
variable over others and then concluding. We can explore the data with
the help of various graphs formed with the help of libraries using any
programming language. In R, GGplot is one of the most famous models
while Matplotlib in Python.

5. Data Modelling:

Once you are done with your study that you have formed from data
visualization, you must start building a hypothesis model such that it
may yield you a good prediction in future. Here, you must choose a good
algorithm that best fit to your model. There different kinds of algorithms
from regression to classification, SVM (Support vector machines),
Clustering, etc. Your model can be of a Machine Learning algorithm.
You train your model with the train data and then test it with test data.
There are various methods to do so. One of them is the K-fold method
where you split your whole data into two parts, one is Train and the
other is test data. On these bases, you train your model.

6. Optimization and Deployment:

You followed each and every step and hence build a model that you feel
is the best fit. But how can you decide how well your model is
performing? This where optimization comes. You test your data and find
how well it is performing by checking its accuracy. In short, you check
the efficiency of the data model and thus try to optimize it for better
accurate prediction. Deployment deals with the launch of your model
and let the people outside there to benefit from that. You can also obtain
feedback from organizations and people to know their need and then to
work more on your model.

2.4 Applications of Data Science:

Fig 2.3

8
CHAPTER : 3
Machine Learning concepts and Applications
Machine learning (ML) allows computers to learn and make decisions without
being explicitly programmed. It involves feeding data into algorithms to
identify patterns and make predictions on new data. Machine learning is used
in various applications, including image and speech recognition, natural
language processing, and recommender systems.

3.1 Why do we need Machine Learning?


Machine Learning algorithm learns from data, trains on patterns, and
solves or predicts complex problems beyond the scope of traditional
programming. It drives better decision-making and tackles intricate
challenges efficiently.

 Solving Complex Business Problems


 Handling Large Volumes of Data
 Automate Repetitive Tasks
 Personalized User Experience
 Self-Improvement in Performance

3.2 What Makes a Machine “Learn”?


A machine “learns” by recognizing patterns and improving its
performance on a task based on data, without being explicitly
programmed.

The process involves:

Data Input: Machines require data (e.g., text, images, numbers) to


analyse.
Algorithms: Algorithms process the data, finding patterns or
relationships.

Model Training: Machines learn by adjusting their parameters based


on the input data using mathematical models.

Feedback Loop: The machine compares predictions to actual outcomes


and corrects errors (via optimization methods like gradient descent).

Experience and Iteration: Repeating this process with more data


improves the machine’s accuracy over time.

Evaluation and Generalization: The model is tested on unseen data


to ensure it performs well on real-world tasks.

9
3.3 Importance of Data in Machine Learning:
Data is the foundation of machine learning (ML). Without quality data,
ML models cannot learn, perform, or make accurate predictions.

 Data provides the examples from which models learn patterns


and relationships.
 High-quality and diverse data improves model accuracy and
generalization.
 Data ensures models understand real-world scenarios and adapt
to practical applications.
 Features derived from data are critical for training models.
 Separate datasets for validation and testing assess how well the
model performs on unseen data.
 Data fuels iterative improvements in ML models through
feedback loops.

Fig 3.0

3.5 Challenges of Machine Learning:

Fig 3.1

10
CHAPTER : 4
PYTHON
Python is a programming language widely used by Data Scientists.

Python has in-built mathematical libraries and functions, making it easier to


calculate mathematical problems and to perform data analysis.

4.1 Why Python for Data Science?


Python is favoured in data science due to its readability, simplicity, and
versatility. Its extensive libraries and frameworks streamline complex
tasks, allowing data scientists to focus on problem-solving rather than
coding intricacies.

Fig 4.1

4.2 Features of Python:

Fig 4.2

11
4.3 Key Libraries and Tools:
NumPy: A fundamental library for numerical operations in Python,
supporting large, multi-dimensional arrays and matrices.

pandas: A powerful library for data manipulation and analysis, offering


data structures like Data Frames to handle structured data efficiently.

Scikit-learn: A comprehensive library for machine learning, providing


simple and efficient data mining and analysis tools.

Matplotlib and Seaborn: Libraries for creating static, animated, and


interactive visualizations, helping to understand data patterns and
trends

Fig 4.3

4.4 Advantages and Disadvantages of Python:

Fig 4.4

12
4.5 Applications of Python:

Fig 4.5

Benefits of Python:

Fig 4.6

4.6 Difference between Python and R Language

Fig 4.7

13
CHAPTER: 5
Python Syntax, Data Types & Operators
Python is known for its clean and readable syntax, which makes it an
excellent language for beginners and professionals working in AI, data
science, and software development.

5.1 Python Syntax


Python syntax refers to the set of rules that define how a Python program is
written and interpreted. One of the most distinctive and beginner-friendly
aspects of Python is its clean and readable syntax. Unlike many other
programming languages that use curly braces {} to define code blocks, Python
uses indentation (whitespace). This means that consistent indentation is not
just a style, but a requirement in Python—usually 4 spaces are used per
indentation level.

A Python program is made up of statements and expressions. Statements are


instructions (like if, for, or def) that perform actions, while expressions are
combinations of values and operators that evaluate to a result. Python is case-
sensitive, so Name, name, and NAME are all treated as different identifiers.

Some key points of Python syntax:

Comments start with # and are ignored by the interpreter. Use them to explain
your code.
Variables do not require a type declaration; the type is inferred from the value
(e.g., x = 10).

Functions are defined using the def keyword, and blocks of code are
structured using colons (:) followed by indented lines.

Control structures like if, elif, else, for, and while are written in a natural,
readable way.

Importing modules is done using the import keyword.

Example:

# This is a comment

def greet(name):

if name:

print (f"Hello, {name}!")

else:

14
print ("Hello, Guest!")

greet("Alice")

Python also supports a REPL (Read-Eval-Print Loop) mode, where you can
type Python code line by line and see immediate results. This makes it great
for quick testing and learning. Overall, Python's syntax emphasizes
readability, simplicity, and consistency, which is why it's so widely loved by
beginners and professionals alike.

Fig 5.1

5.2 Python Data Types:


In Python, data types define the kind of value a variable can hold, and they
are essential for writing correct and efficient programs. Python is a
dynamically typed language, which means you don't need to declare the data
type of a variable explicitly—Python detects it automatically at runtime. The
built-in data types in Python can be broadly categorized into several types:

15
◆ 1. Numeric Types

These include:

int – for integers (e.g., 10, -5)

float – for decimal numbers (e.g., 3.14, -0.01)

complex – for complex numbers (e.g., 2 + 3j)

◆ 2. Sequence Types

These are ordered collections:

str – string, a sequence of characters (e.g., "Hello")

list – mutable sequence of items (e.g., [1, 2, 3])

tuple – immutable sequence (e.g., (4, 5, 6))

◆ 3. Set Types

set – unordered collection of unique items (e.g., {1, 2, 3})

frozen set – like a set but immutable

◆ 4. Mapping Type

dict – a collection of key-value pairs (e.g., {"name": "Alice", "age": 25})

◆ 5. Boolean Type

bool – represents True or False, typically used in conditional expressions

◆ 6. Binary Types

Used to handle binary data:

bytes – immutable sequence of bytes

bytearray – mutable sequence of bytes

memoryview – memory-efficient view of bytes

16
◆ 7. None Type

NoneType – represents the absence of a value, written as None

Example:

a = 10 # int

b = 3.14 # float

c = "Python" # str

d = [1, 2, 3] # list

e = {"key": 1} # dict

f = True # bool

Python also allows you to check the type of a variable using the built-in type()
function, and you can convert between types using type casting, such as int(),
float(), str(), etc. Understanding data types is foundational for writing correct
Python code, as operations and functions behave differently depending on the
type of data they work with.

5.3 Operators:
In Python, operators are special symbols or keywords used to perform
operations on variables and values. Python supports several types of
operators that enable arithmetic operations, comparisons, logical decisions,
bitwise manipulations, and more. These operators make it easier to write
expressions that carry out calculations and control flow in programs.

1. Arithmetic Operators

Used to perform basic mathematical operations:

+ (Addition), - (Subtraction), * (Multiplication), / (Division)

// (Floor Division), % (Modulus), ** (Exponentiation)

Example:

a=5

b=2

print (a + b) # 7

print (a ** b) # 25

2. Comparison (Relational) Operators

17
Used to compare values and return a boolean result:

== (Equal to),!= (Not equal to)

> (Greater than), < (Less than)

>= (Greater than or equal to), <= (Less than or equal to)

Example:

x = 10

y = 20

print (x < y) # True

3. Logical Operators

Used to combine conditional statements:

and – True if both conditions are true

or – True if at least one condition is true

not – Reverses the result (True becomes False)

Example:

a=5

print (a > 2 and a < 10) # True

4. Assignment Operators

Used to assign values to variables:

=, +=, -=, *=, /=, %=, **=, //=

Example:

x=5

x += 3 # x becomes 8

5. Bitwise Operators

Used to perform operations on binary representations:

& (AND), | (OR), ^ (XOR)

~ (NOT), << (Left Shift), >> (Right Shift)

18
Example:

a=5 # 0101

b=3 # 0011

print (a & b) # 1 (0001)

6. Membership Operators

Used to test if a value is a member of a sequence (like list, string, tuple):

in – returns True if value exists

not in – returns True if value does not exist

Example:

fruits = ["apple", "banana"]

print ("apple" in fruits) # True

7. Identity Operators

Used to compare memory locations of objects:

is – returns True if two variables point to the same object

is not – returns True if they do not

Example:

x = [1, 2, 3]

y=x

print (x is y) # True

5.4 Control Statements:


Control statements in Python are used to manage the flow of execution in a
program. They allow you to make decisions, repeat actions, or jump out of
certain code blocks based on conditions. The three main types of control
statements are conditional statements, looping statements, and loop control
statements.

◆ Conditional Statements
These statements let your program make decisions based on certain
conditions. Python uses:

19
if – executes a block if the condition is true

elif – checks another condition if the previous one was false

else – executes a block if all previous conditions were false

Example:

x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")

◆ Looping Statements
Loops are used to repeat a block of code multiple times.

for loop – iterates over a sequence (like a list, string, or range)

while loop – repeats as long as a condition is true

Examples:

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

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

◆ Loop Control Statements


These are used to alter the flow inside loops:

break – exits the loop immediately

continue – skips the rest of the current iteration

20
pass – does nothing, used as a placeholder

Example:

for i in range (5):


if i == 3:
break
print(i) # prints 0, 1, 2

for i in range (5):


if i == 3:
continue
print(i) # prints 0, 1, 2, 4
Control statements are the backbone of decision-making and repetition in
Python, making it possible to write intelligent, responsive, and efficient
programs.

5.4 Strings in Python:


Strings in Python

In Python, a string is a sequence of characters used to represent textual data


such as words, sentences, or even numbers written as text. Strings are
enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """) for
multi-line strings. Python strings are immutable, meaning once a string is
created, its characters cannot be changed individually—you can only create a
new string through operations. Strings support a variety of operations like
concatenation, slicing, and iteration, and are widely used in almost every
Python program.

Python offers many powerful string methods to work with text, such as:

upper () – converts to uppercase

lower () – converts to lowercase

title () – capitalizes each word

21
strip () – removes whitespace from both ends

replace (old, new) – replaces parts of the string

split () – splits the string into a list

join () – joins elements of a list into a single string

find () – returns the index of the first match

startswith () / endswith () – checks how a string begins or ends

Example:

text = “Python is awesome! “

print(text.strip().upper()) # Output: PYTHON IS AWESOME!

Strings can also be indexed and sliced:

word = "Python"

print(word[0]) # P (first character)

print(word[-1]) # n (last character)

print (word [1:4]) # yth (slicing from index 1 to 3)

Python also supports string formatting, which allows you to embed variables
into strings:

Using f-strings: f"Hello, {name}!"

Using .format(): "Hello, {}”. format(name)

Using % formatting (older style): "Hello, %s" % name

A string is a sequence of characters which is enclosed in quotes.

22
There are basically 3 types of operators supported by string:

 Basic Operators: There are two types of basic operators in string. They are
“+” and “*”.
1. Concatenation Operator (+): the concatenation operator concatenates
two strings and forms a new string.
2. Replication Operator (*): It is used to repeat a string number of times
the string will be repeated the number of times is given by the integer
value.
 Membership operators: To test whether a value is present in a sequence.
 Relational Operators: All the comparisons operators i.e., (<,>, <=,>=, == ,!=,
<>)
 Slice Notation: String Slice can be defined as substring which is the part of
string. Therefore, further substring can be obtained from a string.

Strings in Python are versatile and essential, used in everything from simple
output messages to file handling, data parsing, and user input. Their
flexibility and the wide range of methods make them one of the most
important data types in Python.

23
CHAPTER:6
Functions and Scope in Python
In Python: functions, modules, and exception handling. These concepts help
developers write organized, reusable, and error-free code, making Python a
powerful and efficient programming language for AI, data science, and
software development.

6.1 Functions in Python:


Functions in Python

In Python, a function is a reusable block of code that performs a specific task.


Functions help organize code, make it more readable, reduce repetition, and
allow for modular programming. You can define a function using the def
keyword, followed by the function name and parentheses (), which may
include parameters—placeholders for the inputs the function can receive. The
code inside the function is indented and runs only when the function is called.
If a function should return a result, you use the return statement. In

• Built-in Functions such as print (), len (), and range ().

• User-defined Functions, where programmers create their own functions


using the def

keyword.

• Function Parameters and Return Values, enabling functions to accept


input and return

output for better flexibility.

• Lambda Functions, which are small anonymous functions used for quick,
short operations.

Example:

def greet(name):

return f"Hello, {name}!"

print(greet("Alice")) # Output: Hello, Alice!

Python also supports default arguments, where parameters can have default
values:

24
python

Copy

Edit

def greet(name="Guest"):

print (f"Welcome, {name}!")

Functions can take any number of arguments using:

*args for variable-length positional arguments

**kwargs for variable-length keyword arguments

Python also allows anonymous functions using the lambda keyword. These
are short, one-line functions used for simple tasks, especially with functions
like map (), filter (), and sorted ().

Example:

square = lambda x: x * x

print (square (5)) # Output: 25

6.2 Scopes of Python


In Python, scope refers to the visibility and accessibility of variables
within different parts of a program. Scope determines where a variable
is accessible and where not. In order to understand how variables
behave within functions and how they interact with each other, it is
crucial to understand scope.

Python has two main types of scope:

Local scope:
 Variables declared within a function have local scope. They are
accessible only within the function in which they are defined.
 Local variables are created when the function is called and
destroyed when it exits.
 Local variables cannot be accessed from outside the function.

25
Global Scope:
 Variables declared outside of any function or at the top level of a
script have global scope. They are accessible throughout the
program.
 During program startup, global variables are created in memory
and remain there until the program ends.
 Global variables can be accessed from any function within the
program.

Nested scope:
 Python allows nested functions, where one function is defined
inside another.
 During nested functions, the inner function has access to
variables in the outer (enclosed) function.
 The inner function's scope is called "nested scope" because it
includes both its local scope and the enclosing function's scope.

26
CHAPTER: 7
Packages and Modules in Python
Introduction
Python is a high-level, general-purpose programming language widely used in
various domains including data science, machine learning, web development,
and automation. One of Python’s key strengths is its modular structure,
which allows developers to organize code into reusable components. This
modularity is achieved through the use of modules and packages, which play
a vital role in organizing, maintaining, and scaling Python projects effectively.

Modules in Python
A module is a file containing Python code that is written for reuse. It typically
consists of functions, classes, and variables that serve specific functionalities.
The primary goal of a module is to break down large programs into smaller,
manageable, and logically organized parts. This enhances code readability,
promotes reuse, and simplifies debugging and maintenance.

Modules form the foundational building blocks of Python programs. They can
be standard (built-in to Python), third-party (installed externally), or user-
defined (created by the developer). Using modules also allows for separation
of concerns, where each module is responsible for a specific part of the
program logic, reducing complexity in large codebases.

27
Packages in Python
A package is a hierarchical file structure that contains multiple modules
grouped together to form a collection of related functionalities. Packages allow
developers to organize their modules into directories, thereby creating a
scalable project structure. The presence of a special initialization file in the
directory indicates to Python that it should treat the directory as a package.

Packages are essential when working on large projects that involve multiple
components. By categorizing similar modules into packages, developers can
avoid naming conflicts, improve code organization, and enable better
navigation through the codebase. Packages can also contain sub-packages,
allowing for multi-level structuring of code.

Advantages of Using Modules and Packages

The use of modules and packages provides several benefits in software


development:

 Reusability: Code can be written once and reused in different


programs.

 Maintainability: Issues can be isolated and fixed within individual


modules or packages.

 Readability: Well-structured code is easier to understand and modify.

 Namespace Management: Helps avoid conflicts by isolating function


and variable names.

 Scalability: Supports growth of codebase in an organized manner,


especially in large projects.

In professional environments, especially in domains like data science,


modular programming with well-organized packages and modules is
considered a best practice.

Relevance in Data Science


In the field of data science, modular code organization is crucial due to the
multifaceted nature of tasks such as data preprocessing, analysis,
visualization, and model evaluation. Data scientists frequently work with
various Python packages designed for specific tasks. Understanding the
structure and use of modules and packages enables data scientists to build
efficient, reusable, and well-organized code pipelines.

During the course of my internship in the domain of data science, I learned


the importance of modular programming when dealing with data workflows.
The use of packages and modules made it easier to manage code, automate

28
repetitive processes, and collaborate effectively in a team environment. This
approach not only improved the quality of the code but also enhanced overall
productivity.
Modules in Python are essential components that allow programmers to
organize code into separate files and reuse functionality across different
programs. A module is simply a file containing Python code—such as
functions, classes, or variables—that can be imported and used in another
Python script. Python supports various types of modules, including built-in
modules like math, os, and datetime, which come pre-installed and provide
powerful features for mathematical operations, file handling, and date/time
manipulation. Users can also create their own custom modules, known as
user-defined modules, to structure their code better and enhance reusability.
Additionally, third-party modules like numpy, pandas, matplotlib, and flask
can be installed using Python’s package manager pip to perform specific tasks
such as data analysis, visualization, and web development. Modules can be
imported using the import statement, and specific functions or classes can be
brought in using from module import name. By using modules, Python
promotes modular programming, which leads to cleaner, more manageable
code, encourages reusability, reduces redundancy, and improves overall
program structure. Whether for small scripts or large applications, modules
play a vital role in efficient and effective Python development.

29
CHAPTER: 8
EXCEPTION HANDLING IN PYTHON
Introduction
In any programming language, errors are a natural part of the development
process. Python provides a structured way to detect and handle these errors
using a mechanism called exception handling. This allows programs to
respond to unexpected situations without crashing, thereby improving
robustness, user experience, and overall software reliability.

Exception handling is a critical concept in Python, particularly in data-driven


applications where unpredictable user input, file errors, or network issues
can arise. Effective handling of exceptions ensures smooth execution and
helps in debugging, logging, and maintaining code efficiently.

Understanding Exceptions
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions are not necessarily errors
in logic; they often result from conditions that are beyond the control of the
program, such as attempting to access a file that does not exist or dividing a
number by zero.

In Python, exceptions are objects that represent these error conditions. When
an exception occurs, Python immediately stops the current flow of the
program and looks for a way to handle the exception. If not handled, the
program terminates and displays an error message, commonly referred to as
a traceback.

Exception Handling Mechanism


Python uses a structured approach to manage exceptions through specific
keywords that help detect and respond to exceptions. The handling
mechanism allows developers to define blocks of code to try and detect errors,
and to define alternative behaviours in case an error occurs. This approach
separates normal program logic from error handling, which leads to clearer
and more maintainable code.

The exception handling structure in Python includes the following:

 A block to attempt execution.

 One or more blocks to handle specific or general exceptions.

 An optional block that executes regardless of whether an exception


occurred.

30
 An optional block for cleanup actions.

This mechanism provides flexibility and control over how different types of
exceptions are managed and ensures that the program can continue running
or exit gracefully.

Benefits of Exception Handling


Proper use of exception handling brings multiple benefits to Python programs,
especially in complex or user-facing applications. Some key advantages
include:

 Error Isolation: Helps identify exactly where the error occurred without
affecting the rest of the code.

 Improved User Experience: Allows for graceful failure and user-friendly


error messages instead of program crashes.

 Code Clarity: Separates normal program logic from error handling,


making code cleaner and easier to understand.

 System Stability: Prevents unexpected terminations by managing rare


or unanticipated situations safely.

 Maintenance & Debugging: Makes the program easier to maintain and


debug by providing detailed error messages and control flow.

Exception Hierarchy and Custom Exceptions


Python’s built-in exception classes are arranged in a hierarchy, starting from
a base class. This structure allows developers to catch a broad category of
errors or target specific ones. Additionally, Python allows developers to define
their own custom exceptions by creating new classes. This is especially useful
in larger projects, including data science applications, where domain-specific
errors need to be clearly identified and handled.

Custom exception handling improves code readability and gives a clearer


understanding of how certain errors are treated uniquely, contributing to
better error tracking and documentation.

Relevance in Data Science


In the domain of data science, exception handling is crucial due to the
unpredictability of data sources and system resources. Whether it is reading
from external files, processing real-time data, or interacting with APIs,
exceptions can occur at multiple stages. Proper handling ensures that data
pipelines do not break due to a single failure and that logs are maintained for
future analysis.

31
During my internship in the field of data science, I encountered several
scenarios where exception handling became necessary—for instance, when
handling missing values, managing file loading issues, or connecting to
external databases. Implementing structured exception handling helped me
build resilient scripts that could run reliably in different environments with
varying data inputs.

Conclusion
Exception handling is a fundamental aspect of writing robust and
professional-grade Python applications. It allows developers to anticipate and
manage errors effectively, ensuring that programs behave predictably even
under unexpected conditions. In data science and other real-world
applications, the ability to handle exceptions gracefully not only improves
performance but also enhances the reliability and trustworthiness of the
system. My internship experience underscored the importance of mastering
exception handling to create stable, scalable, and user-friendly Python
solutions.

32
CHAPTER: 9
PYTHON DATA STRCTURES
Introduction
Data structures are the foundational building blocks of any programming
language. In Python, data structures are used to store, organize, and manage
data efficiently. They provide a means of performing operations on data and
are essential for solving complex computational problems. Python offers a rich
collection of built-in data structures that are both flexible and easy to use,
which makes the language especially powerful for data science and software
development.

Understanding and utilizing Python’s data structures effectively is crucial for


writing optimized and maintainable code. They support efficient data
manipulation, enable clear program logic, and allow for better performance
across a wide range of applications.

Types of Data Structures in Python


Python provides several built-in data structures, each with unique properties,
performance characteristics, and use cases. These can be categorized into two
main types: primitive and non-primitive data structures.

1. Primitive Data Structures

These are the most basic data types in Python, including:

 Integers

 Floats

 Strings

 Booleans
While not considered data structures in the traditional sense, these primitives
form the basis for more complex types.

2. Non-Primitive Data Structures

These include more advanced structures that are capable of storing multiple
elements and performing operations on them. The primary non-primitive data
structures in Python are:

 Lists: Ordered and mutable collections of elements.

 Tuples: Ordered but immutable sequences.

 Sets: Unordered collections of unique elements.

33
 Dictionaries: Key-value pairs for efficient lookup and storage.

Each of these structures is implemented in a way that allows for dynamic


memory management, and they can grow or shrink as needed, which makes
them more flexible than traditional arrays in other languages.

Importance in Programming and Data Science


Efficient use of data structures is essential for solving real-world problems.
They help in organizing data logically and performing operations such as
insertion, deletion, traversal, and searching in a time-efficient manner.
In the context of data science, choosing the right data structure can greatly
impact the performance and scalability of data pipelines and analytical
models. For example, dictionaries are often used for mapping categorical
variables, while lists and tuples are commonly used for storing data records
or feature sets.

Python’s built-in data structures are often used in combination with third-
party libraries like pandas, which extends their functionality for handling
structured data such as tables and time series.

Key Features of Python Data Structures


 Dynamic Typing: Python data structures can hold mixed data types,
adding flexibility during implementation.

 Memory Efficiency: Python manages memory dynamically, which


simplifies development while still allowing efficient performance.

 Ease of Use: The syntax and operations associated with Python’s data
structures are intuitive and user-friendly.

 Rich Functionality: Python provides a wide range of built-in methods


for manipulating data structures, enhancing productivity and code
readability.

 Extensibility: Built-in structures can be extended or customized to


create more complex structures such as stacks, queues, and graphs
using object-oriented programming.

Applications in Real-World Projects


During the course of my internship in data science, I worked with large and
complex datasets requiring structured organization and efficient data
manipulation. Python data structures played a key role in managing this data
effectively.

34
Tasks such as data cleaning, transformation, and aggregation were greatly
facilitated by using dictionaries, lists, and sets. Understanding the underlying
structure of data allowed me to implement faster and more reliable solutions,
especially when dealing with large-scale operations or real-time data.

Data structures also supported integration with various tools and libraries,
enabling seamless development of end-to-end data workflows.

35
Chapter:10
Lists, Tuples, Sets, Dictionaries and Strings in
Python
List
A list in Python is a dynamic, ordered collection that can store elements of
different data types such as integers, floats, strings, or even other lists (nested
lists). Lists are mutable, so you can change, add, or delete elements without
creating a new list. They are defined using square brackets []. Lists are
versatile and widely used for storing a sequence of items such as a list of
student names, shopping items, or daily temperatures.

Common methods include:

 append () – adds an item to the end

 insert () – inserts an item at a specific index

 pop () – removes and returns the last element

 sort () – sorts the list in ascending order

 reverse () – reverses the list

Example:

fruits = ["apple", "banana", "cherry"]


fruits. Append("orange")

print(fruits)

Output = ['apple', 'banana', 'cherry', 'orange']

String
A string is a sequence of Unicode characters used to represent text. Strings
are immutable, meaning once created, their content cannot be changed. You
can perform various operations on strings like slicing, searching, formatting,
and joining. Strings are defined using single ' or double " quotes, and multiline
strings use triple quotes ''' or """.

Common methods include:

 upper () – converts to uppercase

 lower () – converts to lowercase

 find () – finds a substring

36
 replace () – replaces part of the string

 split () – splits the string into a list

Example:

python

message = "Python is fun"

print (message. Upper ())

Output = PYTHON IS FUN

Tuple
A tuple is a collection similar to a list but immutable, meaning once it's
created, you cannot add, remove, or change elements. Tuples are defined
using parentheses (). Because they are immutable, they can be used as
dictionary keys or elements in a set, which lists cannot do. Tuples are
usually used when the data should not be changed throughout the program,
like coordinates (x, y) or months of the year.

Common operations:

 Accessing elements via index

 Iterating with loops

 Using count () and index () methods

Example:

python

dimensions = (10, 20, 30)

print (dimensions [1])

Output = 20

Advantages:

 Faster than lists (since immutable)

 Safer for storing fixed data

Dictionary
A dictionary is an unordered, mutable collection of key-value pairs. Each
key must be unique and immutable (like strings, numbers, or tuples).
Dictionaries are written using curly braces {}. They are commonly used to
store data like student records, configurations, or any structured data.

37
Common methods:

 get () – safely gets a value by key

 keys () – returns all keys

 values () – returns all values

 items () – returns all key-value pairs

 update () – updates the dictionary with another dictionary

Example:

python

student = {"name": "Alice", "age": 20, "grade": "A"}

print(student["name"])

Output = Alice

Use Cases:

 Storing structured data (e.g., JSON-like)

 Fast lookups based on keys

 Grouping related values together

Set
A set is a collection of unordered, unique items. Sets are useful when you
want to ensure there are no duplicate entries. Sets are mutable, meaning you
can add or remove elements, but they do not support indexing or slicing
because they are unordered. Sets are ideal for operations like union,
intersection, and difference between groups.

Common methods:

 add () – adds an element

 remove () – removes an element

 union () – combines two sets

 intersection () – finds common elements

 difference () – elements in one set but not another

Example:

python

set1 = {1, 2, 3}

38
set2 = {3, 4, 5}

print (set1 & set2)

Output = {3}

39
Chapter: 11
Files and File Handling in Python
Files and File Handling in Python
In Python, file handling allows you to create, read, write, and delete files
directly from your Python program. This is especially useful when you want
to store data permanently, process text files, or interact with external files like
logs, reports, or configurations. Python provides built-in functions for file
handling, and the most common one is the open () function. This function is
used to open a file and returns a file object, which lets you perform various
operations on the file.

When opening a file, you must specify the mode:

 "r" – Read (default mode; file must exist)

 "w" – Write (creates a new file or overwrites if it exists)

 "a" – Append (adds data to the end of the file)

 "x" – Create (creates a file, returns error if file exists)

 Add "b" for binary mode (e.g., "rb" for read binary)

 Add "+" to read and write ("r+", "w+", etc.)

To read data from a file, you can use:

 read () – reads the entire file as a string

 readline () – reads one line at a time

 readlines () – reads all lines and returns a list

To write to a file, use write () or writelines (). After you're done working with a
file, it’s important to close it using close () to free up system resources.
However, the better way to handle files in Python is using a with block (also
called a context manager), which automatically closes the file when done.
Example (writing and reading a file):

python

# Writing to a file

with open ("example.txt", "w") as file:

file.write ("Hello, this is a test file.\n")

file.write("Python is fun!")

40
# Reading from a file

with open ("example.txt", "r") as file:

content = file.read()

print(content)

Advantages of Python's file handling include simplicity, cross-platform


compatibility, and powerful tools for both text and binary file operations. It is
widely used in data processing, saving logs, creating reports, and handling
user inputs.

41
Chapter: 12
Regular Expressions in Python
Regular Expressions (commonly abbreviated as RegEx) are powerful tools
used in Python to search, match, and manipulate strings based on specific
patterns. They are especially useful when you need to validate input (like
emails or phone numbers), extract specific parts of text, or perform complex
text replacements. Python provides the re module for working with regular
expressions. To use it, you must import it with import re.

At the core of regular expressions are patterns made up of special


characters. Some common ones include:

 . – matches any character except newline

 ^ – matches the start of a string

 $ – matches the end of a string

 * – matches 0 or more repetitions

 + – matches 1 or more repetitions

 ? – matches 0 or 1 repetition

 [] – matches any one character inside the brackets

 \d – matches any digit (0-9)

 \w – matches any alphanumeric character

 \s – matches any whitespace character

Common functions in the re module:


 re.match () – checks for a match only at the beginning of a string

 re.search() – searches the whole string for the first match

 re.findall() – returns all non-overlapping matches as a list

 re.sub() – replaces matched patterns with a new string

 re.compile() – compiles a regular expression pattern for reuse

Example:

python

import re

42
text = "My phone number is 9876543210"

pattern = r"\d {10}” # matches exactly 10 digits

match = re.search(pattern, text)

if match:

print ("Phone number found:", match. group ()) # Output: 9876543210

Regular expressions can be tricky at first, but they are incredibly powerful
once mastered. You can build anything from simple string filters to complex
parsers. Python also allows the use of flags like re.IGNORECASE or
re.MULTILINE to control how matching is done.

43
CHAPTER : 13
CONCLUSION
Data Science stands at the forefront of the digital revolution, playing a pivotal
role in transforming raw data into meaningful insights that drive strategic
decisions. It is a multidisciplinary field that blends mathematics, statistics,
programming, and domain knowledge to solve real-world problems. From
healthcare and finance to agriculture and entertainment, data science is being
used to optimize operations, predict future trends, personalize user
experiences, and automate tasks through artificial intelligence and machine
learning.

As the volume of data generated continues to grow at an unprecedented rate,


the demand for skilled data scientists is also increasing rapidly. Tools like
Python, R, SQL, and big data technologies such as Hadoop and Spark have
become essential in managing and analyzing vast datasets efficiently.
Moreover, advancements in deep learning and natural language processing
have opened up new possibilities, enabling machines to understand human
language, recognize images, and even make autonomous decisions.

However, with great power comes great responsibility. It is crucial to address


challenges related to data privacy, security, bias, and ethical use. Data
scientists must not only focus on technical accuracy but also consider the
societal implications of their work.

In conclusion, data science is more than just a technical field—it is a catalyst


for innovation and a bridge between data and meaningful action. As
technology evolves, those equipped with strong analytical skills, curiosity, and
ethical awareness will be at the forefront of shaping a smarter, more data-
driven world.

44

You might also like