0% found this document useful (0 votes)
13 views102 pages

Python FDP

Uploaded by

patil8694srush
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)
13 views102 pages

Python FDP

Uploaded by

patil8694srush
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/ 102

Welcome All

Presentation title 1
FDP Schedule

Presentation title 2
Python Programming
Faculty Development Program
• What is Python
• Operators in Python
• Data types in Python
AGENDA • Loops
• Functions
• Regex Module for Pattern
Matching
• Oops Concepts
• Libraries in Python

Presentation title 4
What Is Python

• Python is a high-level, interpreted and general-


purpose dynamic programming language that
focuses on code readability.
• The syntax in Python helps the programmers to do
coding in fewer steps as compared to Java or C++.
• The language founded in the year 1991 by the
developer Guido Van Rossum.
Python Version

Two Versions is use


Python 2
• Older Version
• Still some softwares use this version
Python 3
• New version 3.12(latest)
• Not backward compatible to Python 2
• We will use 3.8+ version (RECOMMENDED)
Presentation title 7
PRESENTATION TITLE

Simple to program

Python also offers much more error checking than C

Very-high-level language

PYTHON - Has high-level data types built in, such as flexible arrays and dictionaries
• Allows you to split your program into modules that can be reused in other Python programs

FEATURES • Interpreted language

- No need for compilation and linking


• Interpreter can be used interactively

- easy to experiment with features of the language

- test functions during bottom-up program development

8
Strengths and Use cases of Python

The biggest strength of Python is huge collection of standard library which can
be used for the following:
• Machine Learning
• GUI Applications (like Tkinter, PyQt etc. )
• Web frameworks like Django (used by YouTube, Instagram, Dropbox)
• Image processing (like OpenCV, Pillow)
• Test frameworks
• Multimedia
• Scientific computing
• Text processing and many more..
Python scripts

• The Python script is basically a file containing code written in


Python.
• The file containing Python script has the extension ‘.py’
• Different ways to run Python Script:
• Interactive Mode
• Command Line
• Text Editor (VS Code)
• IDE (PyCharm)
• some other ways
Interactive mode

In Python Interactive Mode, you can run


your script line by line in a sequence.

To enter an interactive mode, you will


have to open Command Prompt or
Terminal and type ‘python’ and
press Enter.
Through Command line

• To run a Python script store in a ‘.py’ file in the command line, we have to write ‘python’ keyword
before the file name in the command prompt.
• Example: hello.py
Hi !! Welcome to C-DAC
To run: python hello.py

You can write your own file name in place of ‘hello.py’.


Other Ways..

Text editor (VS code) IDE (Integrated Development Environment)


What is a program?

•A sequence of instructions that specifies how to perform a computation


Print function

• The print() function prints the specified message to the screen, or other standard output device.
• The message can be a string, or any other object, the object will be converted into a string before
written to the screen.
Example:
print("Hi")
print("Hello", "How are you?")
Literals
Python literals are a data type and can hold any value type, such as strings, numbers, and more.
Quoting rules in python (single, double, triple)

• There are two ways to represent strings in python.


• String is enclosed either with single quotes or double quotes.
• Both the ways (single or double quotes) are correct depending upon the requirement.
Example: Correct way: print('python')
Wrong way: print('It's python')

How to print this above statement ??


• The choice between both types (single quotes and double quotes) depends on the
programmer’s choice.
print(" It's Python ")
print(" Hello 'Python' ")
• Generally, double quotes are used for string representation and single quotes are used for
regular expressions, dict keys or SQL.
• Hence both single quote and double quotes depict string in python but it’s sometimes our
need to use one type over the other.
• Triple codes are used as multiline commenting.
Example """ Hii !!! Welcome
This is a multiline comment in python """
Operators in Python

• Operators are used to perform


operations on values and
variables.

• These are the special symbols that


carry out arithmetic, logical,
bitwise computations.
Arithmetic Operators
• Python Arithmetic Operators are used to perform mathematical operations like addition,
subtraction, multiplication, and division.
Assignment Operators

• Assignment operators are used


to assign a value to a variable.
Comparison Operators

To compare the values of two


operands, we can use the
comparison operators.

The result of these operators is


either true or false i.e. a
boolean value
Logical Operators
• To check if the operands satisfy a specific condition, we can use logical operators.
• It is mainly used for decision making.
Identity Operators

• To check if two operands share the


same memory location or not, we can
use the identity operators.
• It doesn't mean that the two
variables are the same, but they are
of the same object.
• These come under the special
operators’ category in python.

Membership Operators

To check if a value or variable is


found in a sequence or not, we can
use membership operators.

These come under the special


operators’ category in python.
Bitwise Operators
Bitwise operators are used to compare the numbers in binary format.
They operate bit by bit on the binary format of the numbers.
Rules for Naming Variables
Google Colab Link For Examples

https://colab.research.google.c
om/drive/1xJss4-
aHye7QeEoZB8YHSwC8InlZ
H0LU?usp=sharing

28
• Numbers and String
There are three numeric types in Python:

• Int

Int, or integer, is a whole number, positive or


negative, without decimals, of unlimited length.

• Float

A number, positive or negative, containing one or


more decimals.

• complex

Complex numbers are written with a "j" as the


imaginary part

Example:

x = 1 # int
y = 2.8 # float
Python 29
z = 1j # complex
To verify the type of any
object in Python, use
the type() function:

Example:
print(type(x))
print(type(y))
print(type(z))
Type Conversion
You can convert from one type to another with
the int(), float(), and complex()
Random
Number
Python does not have
a random() function to make a
random number, but Python has a
built-in module called random that
can be used to make random
numbers:
Strings
• Strings in python are surrounded by either single
quotation marks, or double quotation marks.
• 'hello' is the same as "hello".
• a = "Hello"
print(a)
Multiline Strings
You can assign a multiline string to a variable by using three
quotes
Example:
a = """Hi !!!,
Welcome To,
CDAC Hyderabad."""
print(a)
• To get specific range of characters
• Specify the start index and the end index, separated by a
colon, to return a part of the string
• Example:

Slicing b = "Hello, World!"


print(b[2:5])
Strings Slice From the Start
• To get the characters from the start to position to some
specific range
• Example:
b = "Hello, World!"
print(b[:5])
Slice to the End
Upper Case
• The upper() method returns the string in upper

Modify
case
• Example:

Strings a = "Hello, World!"


print(a.upper())
Lower Case
• The lower() method returns the string in lower
case
• Example:
a = "Hello, World!"
print(a.lower())
String Concatenation

Modify • To concatenate, or combine, two strings you can use


the + operator.

Strings • Example:
a = "Hello"

(Cont..) b =" World!"


c=a+b
print(c)
Lower Case
• The lower() method returns the string in lower
case
• Example:
a = "Hello, World!"
print(a.lower())
• Lists are used to store multiple items in a
single variable.
• List items are ordered, changeable, and
allow duplicate values.
• List items are indexed, the first item has
Lists index [0], the second item has index [1] etc.

(Mutable) List Length


• To determine how many items a list has,
use the len() function
• A list can contain different data types
• Example:
list1 = ["abc", 34, True, 40, "male"]
• Tuples are used to store multiple items in
a single variable.
•Tuple items are ordered, unchangeable,
and allow duplicate values.
•Tuple items are indexed, the first item has
Tuple index [0], the second item has
index [1] etc..
(Immutable) Tuple Length
• To determine how many items a tuple
has, use the len() function
• A tuple can contain different data types
• Example:
tuple1 = ("abc", 34, True, 40, "male")
• Set is used to store multiple items in a
single variable.
•Set items are unordered, unchangeable, and
do not allow duplicate values.
Access Items in Set
• thisset = {"apple", "banana", "cherry"}
for x in thisset:
print(x)

Set Add Items to Set


• thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset)

Remove Items from Set


• thisset = {"apple", "orange", "cherry"}
thisset.remove("orange")
print(thisset)
• Dictionaries are used to store data values in key:value
pairs.
•Dictionary items are ordered, changeable, and does not
allow duplicates.
Access Items in Set
• thisdict = {
"brand": "Ford",
"model": "Mustang"}
x = thisdict["model"]
Add Items
thisdict = {
Dictionary "brand": "Ford",
"model": "Mustang"}
thisdict["color"] = "red"
print(thisdict)
Remove Items
thisdict = {
"brand": "Ford",
"model": "Mustang"}
thisdict.pop("model")
print(thisdict)
File Handling

File handling is an important part of any web application.


Python has several functions for creating, reading,
updating, and deleting files.
The key function for working with files in Python is
the open() function.
The open() function takes two parameters; filename,
and mode.
There are four different methods (modes) for opening a file:
"r" - Read - Default value. Opens a file for reading
"a" - App end - Opens a file for appending
"w" - Write - Opens a file for writing
"x" - Create - Creates the specified file
Syntax: f = open("demofile.txt", "rt")
41
PYTHON

Flow Controls In
Python
Control Structures

• A program’s control flow is the order in which the


program’s code executes.
• The control flow of a Python program is regulated by
conditional statements, loops, and function calls.
• Python has three types of control structures:
• Sequential - default mode
• Selection - used for decisions and branching
• Repetition - used for looping, i.e., repeating a piece of
code multiple times.
Sequential

• Sequential statements are a set of statements


whose execution process happens in a sequence.
• The problem with sequential statements is that
if the logic has broken in any one of the lines,
then the complete source code execution will
break.
Selection/Decision Control
Statements

• In Python, the selection statements are also known


as Decision control statements or branching statements
• The selection statement allows a program to test
several conditions and execute instructions based on
which condition is true.
• Some decision control statements are:
• if
• if-else
• nested if
• if-elif-else
If Condition

• It help us to run a particular code, but only


when a certain condition is met or satisfied.
• if only has one condition to check.
Example:
n = 10
if n % 2 == 0:
print("n is an even number")
If-else Condition
The if-else statement evaluates the
condition and will execute the body
of if only if the test condition is True,
but if the condition is False, then the
body of else is executed.
Example:
n=5
if n % 2 == 0:
print("n is even")
else:
print("n is odd")
Nested if Condition
Nested if statements are an if statement inside
another if statement.
Example:
a = 20
b = 10
c = 15
if a > b:
if a > c:
print("a value is big")
else:
print("c value is big")
elif b > c:
print("b value is big")
else:
print("c is big")
If-elif-else
Condition
The if-elif-else statement is used to conditionally
execute a statement or a block of statements.
Example:
x = 15
y = 12
if x == y:
print("Both are Equal")
elif x > y:
print("x is greater than y")
else:
print("x is smaller than y")
Repetition

A repetition statement is used to repeat a


group(block) of programming instructions.

In Python, we generally have two


loops/repetitive statements:
• for loop
• while loop
For loop • A for loop is used to iterate over a
sequence that is either a list, tuple,
dictionary, or a set.
• The range() function: - We can generate a
sequence of numbers using range()
function.
• Example:
print("For example")
list = [1, 2, 3]
for i in range(len(list)):
print(list[i], end = " \n")
print("2nd example"
for j in range(0,5):
print(j, end = " \n")
While loop
In Python, while loops are used to execute a
block of statements repeatedly until a given
condition is satisfied. Then, the expression is
checked again and, if it is still true, the
body is executed again. This continues until
the expression becomes false.
Example:
m=5
i=0
while i < m:
print(i, end = " ")
i=i+1
print("End")
Break Statement
• The break statement is used inside the loop to exit
out of the loop.
• In Python, when a break statement is encountered
inside a loop, the loop is immediately terminated,
and the program control transfer to the next
statement following the loop.
• In simple words, A break keyword terminates the
loop containing it. If the break statement is used
inside a nested loop (loop inside another loop), it will
terminate the innermost loop.
• We can use Python break statement in both for loop
and while loop. It is helpful to terminate the loop as
soon as the condition is fulfilled instead of doing the
remaining iterations.
• It reduces execution time.
Break
Statement(contd..)
If the condition evaluates to true, then the loop
will terminate. Else loop will continue to work
until the main loop condition is true.
Example: (in for loop)
numbers = [10, 40, 120, 230]
for i in numbers:
if i > 100:
break
print('current number', i)
Break Statement(contd..)

We can use break statement inside while loop


using same approach.
Example: (in while loop)
name = 'CDAC HYD'
size = len(name)
i=0
while i < size:
if name[i].isspace():
break
print(name[i], end=' ')
i=i+1
Break Nested Loop

To terminate the nested loop, use a break statement


inside the inner loop.
Example:
for i in range(1, 11):
print('Multiplication table of', i)
for j in range(1, 11):
if i > 5 and j > 5:
break
print(i * j, end=' ')
print('')
To terminate the outside loop, use
a break statement inside the outer loop
Example:
for i in range(1, 11):

Break Outer Loop # condition to break outer loop


if i > 5:
break
print('Multiplication table of', i)
for j in range(1, 11):
print(i * j, end=' ')
print('')

Presentation title 57
Continue Statement

• The continue statement skip the current iteration


and move to the next iteration.
• In Python, when the continue statement is
encountered inside the loop, it skips all the
statements below it and immediately jumps to
the next iteration.
• In simple words, the continue statement is used
inside loops.
• Whenever the continue statement is encountered
inside a loop, control directly jumps to the start
of the loop for the next iteration, skipping the
rest of the code present inside the loop’s body for
the current iteration.
Continue Statement (contd..)

Example:
numbers = [2, 3, 11, 7]
for i in numbers:
print('Current Number is', i)
# skip below statement if number is greater than 10
if i > 10:
continue
square = i * i
print('Square of a current number is', square)
Continue Statement
In While Loop
We can also use the continue statement inside a while loop.
Example:
name = 'CDAC HYD'
size = len(name)
i = -1
# iterate loop till the last character
while i < size - 1:
i=i+1
# skip loop body if current character is space
if name[i].isspace():
continue
# print current character
print(name[i], end=' ')
Continue Statement in Nested Loop

To skip the current iteration of the nested loop, use


the continue statement inside the body of the inner loop.
Example:
for i in range(1, 11):
print('Multiplication table of', i)
for j in range(1, 11):
# condition to skip current iteration
if j == 5:
continue
print(i * j, end=' ')
print('')
Continue Statement
In Outer Loop
To skip the current iteration of an outside loop, use
the continue statement inside the outer loop.
Example:
for i in range(1, 11):
# condition to skip iteration
# Don't print multiplication table of even numbers
if i % 2 == 0:
continue
print('Multiplication table of', i)
for j in range(1, 11):
print(i * j, end=' ')
print('')
The pass is the keyword In Python, which
won’t do anything. Sometimes there is a
situation in programming where we need
to define a syntactically empty block. We
can define that block with the pass
keyword.

Pass A pass statement is a Python null


statement. When the interpreter finds a

Statement pass statement in the program, it returns


no operation. Nothing happens when
the pass statement is executed.

It is useful in a situation where we are


implementing new methods or also in
exception handling. It plays a role like a
placeholder.
Pass Statement(contd...)

Example:
months = ['January', 'June', 'March', 'April']
for mon in months:
pass
print(months)
Python

Introduction To Pyt hon: ht tps://colab.r es earch.google.com/drive/1xJss 4-


aHye7Q eEoZB8YHSw C8InlZH0LU?usp=sharing

E X A MP L ES Data types: ht tps://colab.r es earch.google.com/drive/19yBp0-


L5qEEG OLSKcDouKwf6uQ 6R3oLe?usp=sharing
-COLAB
Loops: https://colab.researc h. google.com/drive/1wR fBmK4ePf_352 bPg_2O -
t2deaAZvqUz

65
Functions
A f un ct ion is A bloc k of code wh ic h only r un s wh en it i s cal led.
Yo u c a n p a s s d a t a , k n o w n a s p a r a m e t e r s , i n t o A f u n c t i o n .
A f un ct ion can re tu r n data as A re sult .
Fun ct ion is def ine d u sing t he def keyword.
Example:
def my_function():
p rint (" hell o fr om A f unct i o n")

my_f unct io n() #c al li ng A f unct i on


Parameters vs Arguments

T he t er m s par am eter an d a rgument can be u sed for t h e sam e


t hin g in for mati on th at are passed int o a f un ct ion.
Fro m a functio n' s p er spe ctive:

• A pa ram e te r is t he va riable liste d insid e t he


pa ren t he ses in th e fu n ct ion de fin it ion .
• A n ar gu m en t is t h e va lue t ha t is sen t to th e
f u n c t i o n wh e n i t i s c a l l e d .
Arbitrary Arguments
If t he nu m b er o f a r g u men t s i s u n k n ow n , a d d a * b ef or e t h e p ar a m et er
name .

Exampl e:

Def my_f uncti on ( * subjec ts):


pri nt("the subj ect i s " + subje cts[2 ])

my_f uncti on ( "m aths ", "sci ence", "engli sh")


Keyword arguments

Yo u c a n a l s o s e n d a r g u m e n t s w i t h t h e k e y = v a l u e s y n t a x .

Exampl e:
def my_function(key3, key2, key1):
print("the subject is " + key1)

my_function(key1="maths", key2="science", key3="english")


Arbitary Keyword arguments

I f t h e nu m b e r o f k ey w o r d a r gu m e n t s is u n k n ow n , a d d a
d o u ble * * b ef or e t h e p ar a m et er n a me.

Exampl e:
def my_function(**key):
print("the subject is " + key["key3")

my_function(key1="maths", key2="science", key3="english")


Passing a List as an Argument

Yo u c a n s e n d a n y d a t a t y p e s o f a r g u m e n t t o a f u n c t i o n ( s t r i n g ,
n u m b e r, l i s t , d i c t i o n a r y e t c . ) , A n d i t w i l l b e t r e a t e d a s t h e s a m e
d ata type insi d e the f unctio n.
Exampl e:
de f my_ f un cti on ( fo od ):
fo r x i n fo od :
p rin t(x)

fru its = ["ap ple", "ba na na ", "cherr y"]

my_function (fruits)
Return Values
To le t a fu n c ti o n r e t u r n a va l u e , u s e t h e r e t u r n s t a t e me n t

E xa m p le:
def my_function(x):
return 5 * x

print(my_function(3))
print(my_function(5))
print(my_function(9))
Python RegEx

• A regex, or re gular expre ssion, is a


sequenc e of cha ra cters tha t fo r ms a sea rch
pattern.

• Regex can be used to che ck if a string


contains the spe cified search patter n.
Regex module

• Python has a buil t-i n pa c ka g e ca ll ed re,


w hic h ca n b e u s e d t o w o rk w it h r e g u la r
expre ssions.
RegEx Function
T he re m od ul e o f fe rs a set o f func ti o ns tha t
a ll ow s us t o sea rc h a st ring f o r a m at c h.
Match Object

• A ma tch o bje ct is a n obj ect co nta ini ng info r ma ti on a bo ut the sea rch a nd
the result.

• T he ma t ch o b j ect ha s p r op e r t i es an d me t ho ds u s ed t o r e t r ieve
i nfo rm ati o n abo ut the sea rch , a nd the re sult.
.span() returns a tuple containing the start, and end positions of the match.
.string returns the string passed into the function
.group() returns the part of the string where there was a match
METACHARAC
metacharacters
TERS ARE
CHARACTERS
WITH A
SPECIAL
MEAN ING.
Special characters

A special
se qu en ce i s
a \ f o l l o we d b y
o ne of t he
c ha ra c te rs in the
l i s t b e l o w, a n d
has a special
me an in g
Sets

A set is a set of
c ha ra c te rs in sid e
a pa i r o f sq ua re
b r a c ke t s [ ] w i t h
a spe c ia l
me an in g
Pattern Matching

Exampl e:
P hon enu mr e ge x = r e. Com p ile( r '\ d\ d\ d - \ d \ d \ d- \ d\ d \ d \ d' )
M o = p hon enu mre ge x.S earch ( ' my num b er i s 415 - 555- 4242.' )
P r i nt ( ' ph o ne nu m ber fo u nd : ' + m o. G r o u p ( ))
python

The main concept of OOPs is to bind the data

Object and the functions that work on that together

Oriented as a single unit so that no other part of the


code can access this data.
Prog ramming
Python Class

A class is a collection of objects. A class contains the


blueprints or the prototype from which the objects are
being created.

80
Class
python

Syntax of Class:
class ClassName:
# Statement-1 Eg: class Dog:
…. …....
# Statement-N
sound = "bark"
• Classes are created by keyword class.

• Attributes are the variables that belong to a class.

• Attributes are always public and can be accessed using the dot (.) operator.

81
python

Object

• The object is an entity that has a state and behavior associated with it.

• It may be any real-world object like a mouse, keyboard, chair, table, pen, etc.
Integers, strings, floating-point numbers, even arrays, and dictionaries, are all
objects.

• More specifically, any single integer or any single string is an object.

• The number 12 is an object, the string “Hello, world” is an object

82
python

Object
Object Consists of:

• State

• Behavior

• Identity

Example:

• The identity can be considered as the name of the dog.

• State or Attributes can be considered as the breed, age, or color of the


dog.

• The behavior can be considered as to whether the dog is eating or sleeping.

83
Co nstr u cto rs a nd Destr uctor s
Co ns tr u cto rs Des tr ucto r s

• Used for instantiating an object. • Destructors are called when an object gets destroyed.
• Th e task of constructors is to initialize( assign • In Pyth on, destructors are not needed as much as in
values) to th e data members of the class wh en C++ because P ython has a garbage collector that
an object of the class is created. handles memory management automatically.
• In Pyth on the __init__() method is called th e • Th e __del__() met hod is a known as a destr uctor
cons tr uctor and is always call ed w hen an object method in P ython. It is called when all references to
is created. th e object have been del eted i.e when an object is
garbage collected.
Syntax of const r uctor declaration :
Syntax of destructor declarat ion :
def __init__(self):
def __del__(self):
# body of the constructor
# body of destructor
Types:
D efau lt P arame teriz e d c onstru ctor

84
Python

Oops Conce pts

• Inh eritance
• Po lymo rphism
• Abstra ction
• Encapsulatio n

85
Python

Inheritance

Inh erit an ce is def in ed as t he m echa nism of


inher it in g t he pro per ties o f t he ba s e cla ss t o th e
child cla ss
The Pa rent cla ss is t he cla ss wh ich pr ovides
fea tu res t o a no th er class . The par ent class is also
Types of Inheritance known a s Ba s e cla ss o r Sup ercla s s.

• Single The C hild cla ss is t he cla ss wh ich r eceives


fea tu res fr o m a no th er cla ss . The child cla ss is a lso
• Multiple known a s t he Der ived C la s s o r Sub clas s.
• Multilevel
• Hierarchical
• Hybrid
86
PYTHON

S i n gl e I n h e r i t an c e

Singl e inhe ri ta nce enabl es a derived cl ass


to inhe ri t pro per ti es from a single pa re nt
c lass.

87
PYTHON

Multiple Inheritance

• A c l a s s c an b e d er i ve d f ro m m o re th a n on e b a se
c l a ss t h i s t yp e o f i nh e r i ta n ce i s c al l e d m u l t i p l e
i n h e ri t a nc e s .
• I n m u l ti pl e i n he r i t an c e s, al l t h e f ea tu r e s of t he
b as e c l a s se s a re i n he r i t e d i nt o t he de r ive d c l as s .

88
PYTHON

M u l t i l eve l I n h e r i t a n c e

• In mu lt ilevel inh erit a nce, feat ur es of t he ba s e


cla ss a nd t he der ived cla ss a r e fur th er in her it ed
int o th e new der ived c la s s.
• This is sim ila r to a r elat ions hip re pr esent ing a
child a nd a g r an df at her.

89
PYTHON

Hierarchical Inheritance

• W h en m or e t h an o n e de r ive d c l as s a re c re at e d fr om a
s i n gl e b as e t h i s t yp e o f i nh e r i ta n ce i s c al l e d h i e r ar c h i c al
i n h e ri t a nc e .
• I n t h i s p ro g ra m , we h ave a p ar e nt (b as e ) c l a ss a n d t w o or

m o re c hi l d( de ri ved ) c l a ss e s.

90
PYTHON

H y b r i d I n h e r i t an c e

Inh eritance c onsisti ng o f mul ti ple


types of inhe ri ta nce is c all ed
hybrid inhe ri ta nce.

91
PYTHON

• Po l ym or p h i sm s i m p l y m e an s h av i n g m a ny
fo r m s .
• T h i s co de de m on s tr at e s t h e c on c e p t of
i n h e ri t a nc e a n d m et h od ove r r i d i ng i n
Py t h on c l a s se s .

Pol ym or p hi s m • I t s h ow s h ow s ub c l a ss e s c an ove r r i de
m e t h ods de fi n e d i n t h ei r pa r en t c l a s s to
p rovi de s p ec i f i c b e h av i or wh i l e st i l l
i n h e ri t i n g ot h e r m e t ho ds f r om th e pa re n t
c l a ss .

92
E n c ap s u l at i o n

• Enca ps ula tio n is a m echa nism o f w r ap p ing the d a ta


(va r iab les) and co d e act ing on the d a ta (meth od s )
to get her as a s ingle unit.
• Acces s mo d if iers in t he co ncep t o f Enca ps ula tion an d
d at a hiding.
• P ublic: Acces s ible f rom in side or out side the clas s .
• P riva te: Acces s ible o nly insid e cla ss . Def ine a pr iva te
mem ber by p ref ixing th e memb er na me w it h two
und er s cor es . Eg : __a ge
• P ro tect ed: A ccess ib le . fr o m ins ide t he cla s s a nd its
Access Modifiers s ub-cla ss . Def ine a pr o tect ed memb er by pr efix ing the
•Public mem ber name with an u nder s core Eg : _p oint s
•Private
•Protected 93
Python

• It hides unnecessary code details from


the user.
• Also, when w e do not want to give out
Abstraction sensitive par ts of our code
implementation and this is where data
abstraction came.

94
Python

• These are various Object Oriented Programming


concepts in Python.

OOPS • Online Reference:

W3schools

GeeksforGeeks

95
Python

• Pandas → Data manipulation and analysis library

• NumPy → Numerical computing with powerful arrays

Libraries in • Scikit-learn → Machine Learning library for predictive


modeling
py t h o n
• Together → Foundation of Python Data Science
Ecosystem

96
PRESENTATION TITLE

• Pr ovi des ndarray: fast , efficient ,


mult idimensional ar r ays

• Suppor ts vectorized operat ions (faster than


Pyt hon loops)

• Common F unctions:
N U M PY • np.ar ray([1,2,3])

• np.mean(), np.std(), np.dot()

• Applicat ions : Linear A lgebr a, Statis tics, Image


Pr ocessing

97
PRESENTATION TITLE

• Built on NumPy → adds DataFrames & Series

Key Features:

• Data cleaning & preprocessing

PA N DA S • Handling CSV/Excel/SQL data

• Grouping, merging, reshaping data

Example:
import pandas as pd
df = pd.read_csv("data.csv")
print(df.head())

98
PRESENTATION TITLE

Provides easy-to-use ML models:


• Classification, Regression, Clustering
• Dimensionality Reduction (PCA)
Workflow:
• Import dataset
S C I K I T- • Split into train/test
L E A RN • Choose model → train → predict
Example:
from sklearn.linear_model import LogisticRegression
model = LogisticRegression().fit(X_train, y_train)

99
PRESENTATION TITLE

All Together

• NumPy → numerical computations (arrays, math)

• Pandas → clean & organize dataset

• Scikit-learn → build ML model

Example Workflow:

• Load data with Pandas

• Process arrays with NumPy

• Train/predict with Scikit-learn

100
Python

Introduction To Pyt hon: ht tps://colab.r es earch.google.com/drive/1xJss 4-


aHye7Q eEoZB8YHSw C8InlZH0LU?usp=sharing

Data types: ht tps://colab.r es earch.google.com/drive/19yBp0-


L5qEEG OLSKcDouKwf6uQ 6R3oLe?usp=sharing

Loops: https://colab.researc h. google.com/drive/1wR fBmK4ePf_352 bPg_2O -


E X A MP L ES t2deaAZvqUz

-COLAB Functi ons and Regex:


https://colab.research.google.com/drive/18Nw61_L60MBM IaDE YT9z -
iSPDfNwjgKk?usp=sharing

OOPS: https://colab.research.google.com/drive/1x0yurbjJRvdoi a0 -
MT Q 56KbLdR6l s02N?usp=s haring

101
THANK YOU
Any Queries ??

Presentation title 102

You might also like