Python
Presents
-Krishna katigar
What is Python
Python is a High-level, Object Oriented Programming Language with Object, Modules, Thread,
Exception..Etc
It is simple but yet Powerful Programming language
Python is a Programming Language that coombines features of C and Java
Application For Python
Web Application – Django, Pyramid, Flask, Bottle
Desktop[ GUI Application – Tkinter]
Console Based Application
Games and 3D Application
Mobile Application
Scientfic and Numeric
Data Science
Machine Learning – scikit-learn and TensorFlow
Data Analysis – Mataplotib, Scaborn
Business Application
Python Compilor – Python Compilor Converts the Program source code into Byte code.
Type of Python Compilors:
• Cpython
• Jpython/Jython
• PyPy
• RubyPython
• IronPython
• StacKless Python
• AnacondaPython
Compilor
Source code/
program
Compile and Run
Write a Source code/Program
Compile the program using ptython cmpilor
Compile converts the Python Program into Byte Code
Copmputer/Machine can not understand Byte Code sowe Convert into Machine Code
using PVM
PVM uses an interpreter which understands the Byte Code and converts it into machine
code
Machine Coe instructions are then Executed by the processor and results are displayed.
Byte Code Computer
Binary Code/
Machine Code
File name.py File name.pyc
Compile
using
Python
Compilor
Run
Program
Using
PVM
Output
PVM(Python Virtual Machine)
Python Virtual machine(PVM) is Program which provides programming
environment
The role of PVM is t convert the Byte code Instructions into machine Code so
the Computer can execute those machine code instrucions and display the
output.
Interpreter converts the byte code into machin code and sends that machine
code to the computer
Source code/
program
Byte Code Computer
Binary Code/
Machine Code
Compile
using
Python
Compilor Output
Interpreter
PVM
Identfier
An idenifier is a name having a few letters, numbers and special characters_(Underscore).
It Should always start with a non-numeric character.
Its is used to identify a variable, function, symbolic constant, class etc.
Ex :
• X2
• PI
• Sigma
Keywords or Reserved Words
Keyword means which contains some special meaning.
Python language uses the dollowing keywords which are not avaiable to users to ue them as
identifires.
Python – Data Types
Numeric Dictionary
Integer String
Boolean Set
Sequence
Type
Complex
Number
Float
List
Tuple
Data Types
Dictionary
What is a Python Dictionary?
A dictionary is a built-in Python data type that stores key-value pairs.
Keys must be unique and immutable (e.g., strings, numbers, tuples).
Values can be of any data type.
Common Dictionary Methods
keys(): Returns a view of all keys.
values(): Returns a view of all values.
items(): Returns a view of key-value pairs.
get(key, default): Retrieves value for a key with an optional default.
pop(key, default): Removes and returns value for a key.
Set
What is a Python Set?
A set is an unordered collection of unique elements.
Sets are mutable and do not allow duplicate values.
Key Operations on Sets
Adding Elements: Use add() method.
Removing Elements: Use remove() or discard() methods.
Checking Membership: Use in keyword.
Common Set Methods
union(other_set): Returns a set with elements from both sets.
intersection(other_set): Returns a set with common elements.
difference(other_set): Returns a set with elements in the current set but not
in the other.
difference_update(other_set): Updates the set to remove elements found in
the other set.
symmetric_difference(other_set): Returns elements in either set but not
both.
List
Lists are mutable sequences that can hold multiple items.
You can manipulate lists using various built-in methods.
Common List Operations:
Adding items: append(), extend()
Removing items: remove(), pop()
Accessing items: list[index]
Tuple
What is a Python Tuple?
A tuple is an immutable sequence of Python objects.
Tuples are used to store multiple items in a single variable.
Unlike lists, tuples cannot be modified after their creation.
Key Operations on Tuples
Accessing Elements: Use indexing, similar to lists.
Slicing: Extract a portion of the tuple.
Concatenation: Combine tuples with +.
Repetition: Repeat tuple elements with *
Common Tuple Methods
count(value): Returns the number of occurrences of a value.
Index(value): Returns the index of the first occurrence of a value
Tuple Unpacking
Tuple unpacking allows you to assign elements of a tuple to multiple variables in a single statement.
String
Strings are sequences of characters.
Python provides several methods for manipulating strings.
Common String Operations:
Accessing characters: string[index]
Slicing: string[start:end]
String methods: upper(), lower(), replace()
Conditional Statements
Conditional statements allow the program to make decisions based on conditions.
They control the flow of execution.
Syntax:
if condition:
# code to execute if condition is True
elif another_condition:
# code to execute if another_condition is
True
else:
Loops in Python
Loops are used to execute a block of code
repeatedly.
They help automate repetitive tasks.
Types of Loops:
For Loop: Iterates over a sequence (like a list
or a range).
While Loop: Continues to execute as long as a
specified condition is True.
Example: For Loop
for i in range(5):
print(i)
Example: While Loop
count = 0
while count < 5:
print(count)
count += 1
What is a Function?
A function is a reusable block of code that performs a specific task.
Functions helps in organizing code, making it modular and easier to maintain.
Syntax:
def function_name(parameters):
# code to execute
return value
Example:Simple Function
Copy code
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
What is Scope?
Scope refers to the visibility or accessibility of
variables in different parts of your code.
There are two main types of scope:
●
Local Scope: Variables defined within a
function.
●
Global Scope: Variables defined outside of any
function.
Example: Local vs Global Scope
x = 10 # Global variable
def my_function()
y = 5 # Local variable
print("Inside function:", x, y)
my_function()
print("Outside function:", x)
# print(y) # This would raise an error
●
The variable x is accessible both inside and outside the
function, while y is only accessible inside my_function.
●
Trying to print y outside the function would raise an error.
Parameters and Return Values
Parameters: Variables that are passed into a
function when it is called.
Return Values: The output that a function
produces when it is called.
Benefits:
Functions can perform operations with
different inputs and return results.
Example: Function with Parameters and
Return
def add(a, b):
return a + b
result = add(3, 5)
print(result) # Output: 8
add(2,5)
The add function takes two parameters, a and
b, and returns their sum.
The result of the function call is stored in the
variable result and printed.
Introduction to Modules
What are Modules?
Explanation:
A module is a file containing Python code (functions, classes, variables).
Modules allow for code organization and reuse.
Python has many built-in modules, and you can create your own.
Example: Creating a Custom Module
Code (in a separate file named mymodule.py):
def multiply(a, b):
return a * b
How to Import Modules
Use the import statement to include a module in your code.
You can import specific functions or classes or import the entire module.
Syntax:
Import module_name
from module_name import
function_name
Importing a Custom Module
Import mymodule
result = mymodule.multiply(4, 5)
print(result) # Output: 20
Here, we define a function multiply in a file called mymodule.py.
This module can be imported into other Python files.
Introduction to Object-Oriented Programming (OOP)
•OOP is a programming paradigm based on the concept of "objects"
•Objects are instances of classes which can contain:
•Data (attributes)
•Functions (methods)
•A Class is a blueprint for creating objects
•It defines attributes and methods common to all objects of that type
•An Object is an instance of a class
•Created using the class name
•The __init__ method a special method called when an object is created
•Used to initialize object attributes
Constructors & Inheritance in Python
•Special method used to initialize objects
•Defined using __init__()
•Automatically called when an object is created
Types of Constructors
Default Constructor: No arguments
Parameterized Constructor: Accepts arguments to set
values
Constructors & Inheritance in Python
•Allows a class (child) to inherit properties and methods from another class (parent)
•Promotes code reuse
Types of Inheritance
• Single
• Multiple
• Multilevel
• Hierarchical
What is Polymorphism?
Polymorphism means many forms
The same method name can have different behaviors depending on
the object
Makes code more flexible and extensible
Exception Handling in Python
•An exception is an error that occurs during program execution
•Without handling, it crashes the program
•Python provides a way to catch and handle exceptions using:
•try
•except
•Finally
The try-except Block
• Code that might raise an error is written inside try
• Error handling code goes inside except
•finally block always runs, no matter what
•Used for cleanup actions (like closing files)
What is a Regular Expression?
A regular expression (regex) is a special pattern used to search,
match, or extract data from text.
Used in:
Form validation (emails, phone numbers)
Data extraction (scraping, logs)
Text search and replace
Python uses the re module to work with regex.
Basic Regex Syntax
Pattern Meaning Example Match
d Digit (0-9) 2, 98
w
Word character (a-z, A-Z, 0-9,
_)
hello_123
. Any character except newline a.c matches abc, axc
+ One or more a+ matches a, aa, aaa
* Zero or more lo* matches l, lo, loo
[] Character set [aeiou] matches vowels
^ Start of string ^Hi matches "Hi there"
$ End of string end$ matches "The end"
Introduction to File Handling
File handling allows Python to create, read, write, and delete
files.
It is useful for:
• Storing data permanently
• Logging
• Reading configuration or data files
• Built-in functions:
• open(), read(), write(), close()
File Modes:
Mode Description
'r' Read (default)
'w' Write (overwrite)
'a' Append
'r+' Read and write
Reading and Writing a File
# Writing to a file
with open("demo.txt", "w") as f:
f.write("Hello, Python!nFile handling is easy.")
# Reading the file
with open("demo.txt", "r") as f:
content = f.read()
print(content)
Appending and Reading Lines
# Appending new data
with open("demo.txt", "a") as f:
f.write("nThis is a new line.")
# Reading line by line
with open("demo.txt", "r") as f:
for line in f:
print(line.strip())
Web Scrapping
Presents
-Krishna katigar
What is Web Scraping?
Web scraping is the process of automatically
extracting data from websites.
It helps collect information from websites in a
structured format.
Often used in data analysis, market research, price
monitoring, and more.
Why Use Web Scraping?
•Automates data collection.
•Saves time and reduces manual work.
•Useful when APIs are unavailable.
•Enables large-scale data extraction.
Common Use Cases
•Price comparison sites
•News aggregation
•Social media sentiment analysis
•Job listing aggregators
•Real estate market analysis
Web Scraping Tools
BeautifulSoup (Python)
Scrapy (Python)
Selenium (Browser automation)
Puppeteer (Node.js)
Requests (Python library for making HTTP
requests)
Introducing BeautifulSoup
• A Python library used to extract data from HTML and XML
files.
• Parses the page and creates a parse tree for easy data
extraction.
• Often used with requests library for fetching web pages
Installing BeautifulSoup
pip install beautifulsoup4
pip install requests
Simple Web Scraping Example
import requests
from bs4 import BeautifulSoup
url = "https://example.com"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
title = soup.title.text
print("Page Title:", title)
Features of BeautifulSoup
•Simple and Pythonic syntax.
•Powerful tree traversal and searching.
•Supports multiple parsers (like html.parser, lxml,
etc.).
•Easy to integrate with other Python libraries.
www.docketrun.com
Confidential and Proprietary. Copyright (c) by DocketRun Tech Pvt Ltd. All Rights
Reserved All images are actual or prototype DocketRun products
Email ajay@docketrun.com
Contact: +91-9449034387 / +91-9353412662
Website www.doketrun.com
Address DocketRun Tech Pvt. Ltd.
Hubballi, Karnataka - 580030, India

Docketrun's Python Course for beginners.pptx

  • 1.
  • 2.
    What is Python Pythonis a High-level, Object Oriented Programming Language with Object, Modules, Thread, Exception..Etc It is simple but yet Powerful Programming language Python is a Programming Language that coombines features of C and Java
  • 3.
    Application For Python WebApplication – Django, Pyramid, Flask, Bottle Desktop[ GUI Application – Tkinter] Console Based Application Games and 3D Application Mobile Application Scientfic and Numeric Data Science Machine Learning – scikit-learn and TensorFlow Data Analysis – Mataplotib, Scaborn Business Application
  • 4.
    Python Compilor –Python Compilor Converts the Program source code into Byte code. Type of Python Compilors: • Cpython • Jpython/Jython • PyPy • RubyPython • IronPython • StacKless Python • AnacondaPython Compilor
  • 5.
    Source code/ program Compile andRun Write a Source code/Program Compile the program using ptython cmpilor Compile converts the Python Program into Byte Code Copmputer/Machine can not understand Byte Code sowe Convert into Machine Code using PVM PVM uses an interpreter which understands the Byte Code and converts it into machine code Machine Coe instructions are then Executed by the processor and results are displayed. Byte Code Computer Binary Code/ Machine Code File name.py File name.pyc Compile using Python Compilor Run Program Using PVM Output
  • 6.
    PVM(Python Virtual Machine) PythonVirtual machine(PVM) is Program which provides programming environment The role of PVM is t convert the Byte code Instructions into machine Code so the Computer can execute those machine code instrucions and display the output. Interpreter converts the byte code into machin code and sends that machine code to the computer Source code/ program Byte Code Computer Binary Code/ Machine Code Compile using Python Compilor Output Interpreter PVM
  • 7.
    Identfier An idenifier isa name having a few letters, numbers and special characters_(Underscore). It Should always start with a non-numeric character. Its is used to identify a variable, function, symbolic constant, class etc. Ex : • X2 • PI • Sigma
  • 8.
    Keywords or ReservedWords Keyword means which contains some special meaning. Python language uses the dollowing keywords which are not avaiable to users to ue them as identifires.
  • 9.
    Python – DataTypes Numeric Dictionary Integer String Boolean Set Sequence Type Complex Number Float List Tuple Data Types
  • 10.
    Dictionary What is aPython Dictionary? A dictionary is a built-in Python data type that stores key-value pairs. Keys must be unique and immutable (e.g., strings, numbers, tuples). Values can be of any data type. Common Dictionary Methods keys(): Returns a view of all keys. values(): Returns a view of all values. items(): Returns a view of key-value pairs. get(key, default): Retrieves value for a key with an optional default. pop(key, default): Removes and returns value for a key.
  • 11.
    Set What is aPython Set? A set is an unordered collection of unique elements. Sets are mutable and do not allow duplicate values. Key Operations on Sets Adding Elements: Use add() method. Removing Elements: Use remove() or discard() methods. Checking Membership: Use in keyword. Common Set Methods union(other_set): Returns a set with elements from both sets. intersection(other_set): Returns a set with common elements. difference(other_set): Returns a set with elements in the current set but not in the other. difference_update(other_set): Updates the set to remove elements found in the other set. symmetric_difference(other_set): Returns elements in either set but not both.
  • 12.
    List Lists are mutablesequences that can hold multiple items. You can manipulate lists using various built-in methods. Common List Operations: Adding items: append(), extend() Removing items: remove(), pop() Accessing items: list[index]
  • 13.
    Tuple What is aPython Tuple? A tuple is an immutable sequence of Python objects. Tuples are used to store multiple items in a single variable. Unlike lists, tuples cannot be modified after their creation. Key Operations on Tuples Accessing Elements: Use indexing, similar to lists. Slicing: Extract a portion of the tuple. Concatenation: Combine tuples with +. Repetition: Repeat tuple elements with * Common Tuple Methods count(value): Returns the number of occurrences of a value. Index(value): Returns the index of the first occurrence of a value Tuple Unpacking Tuple unpacking allows you to assign elements of a tuple to multiple variables in a single statement.
  • 14.
    String Strings are sequencesof characters. Python provides several methods for manipulating strings. Common String Operations: Accessing characters: string[index] Slicing: string[start:end] String methods: upper(), lower(), replace()
  • 15.
    Conditional Statements Conditional statementsallow the program to make decisions based on conditions. They control the flow of execution. Syntax: if condition: # code to execute if condition is True elif another_condition: # code to execute if another_condition is True else:
  • 16.
    Loops in Python Loopsare used to execute a block of code repeatedly. They help automate repetitive tasks. Types of Loops: For Loop: Iterates over a sequence (like a list or a range). While Loop: Continues to execute as long as a specified condition is True. Example: For Loop for i in range(5): print(i) Example: While Loop count = 0 while count < 5: print(count) count += 1
  • 17.
    What is aFunction? A function is a reusable block of code that performs a specific task. Functions helps in organizing code, making it modular and easier to maintain. Syntax: def function_name(parameters): # code to execute return value Example:Simple Function Copy code def greet(name): return f"Hello, {name}!" print(greet("Alice"))
  • 18.
    What is Scope? Scoperefers to the visibility or accessibility of variables in different parts of your code. There are two main types of scope: ● Local Scope: Variables defined within a function. ● Global Scope: Variables defined outside of any function. Example: Local vs Global Scope x = 10 # Global variable def my_function() y = 5 # Local variable print("Inside function:", x, y) my_function() print("Outside function:", x) # print(y) # This would raise an error ● The variable x is accessible both inside and outside the function, while y is only accessible inside my_function. ● Trying to print y outside the function would raise an error.
  • 19.
    Parameters and ReturnValues Parameters: Variables that are passed into a function when it is called. Return Values: The output that a function produces when it is called. Benefits: Functions can perform operations with different inputs and return results. Example: Function with Parameters and Return def add(a, b): return a + b result = add(3, 5) print(result) # Output: 8 add(2,5) The add function takes two parameters, a and b, and returns their sum. The result of the function call is stored in the variable result and printed.
  • 20.
    Introduction to Modules Whatare Modules? Explanation: A module is a file containing Python code (functions, classes, variables). Modules allow for code organization and reuse. Python has many built-in modules, and you can create your own. Example: Creating a Custom Module Code (in a separate file named mymodule.py): def multiply(a, b): return a * b
  • 21.
    How to ImportModules Use the import statement to include a module in your code. You can import specific functions or classes or import the entire module. Syntax: Import module_name from module_name import function_name
  • 22.
    Importing a CustomModule Import mymodule result = mymodule.multiply(4, 5) print(result) # Output: 20 Here, we define a function multiply in a file called mymodule.py. This module can be imported into other Python files.
  • 23.
    Introduction to Object-OrientedProgramming (OOP) •OOP is a programming paradigm based on the concept of "objects" •Objects are instances of classes which can contain: •Data (attributes) •Functions (methods) •A Class is a blueprint for creating objects •It defines attributes and methods common to all objects of that type •An Object is an instance of a class •Created using the class name •The __init__ method a special method called when an object is created •Used to initialize object attributes
  • 24.
    Constructors & Inheritancein Python •Special method used to initialize objects •Defined using __init__() •Automatically called when an object is created Types of Constructors Default Constructor: No arguments Parameterized Constructor: Accepts arguments to set values
  • 25.
    Constructors & Inheritancein Python •Allows a class (child) to inherit properties and methods from another class (parent) •Promotes code reuse Types of Inheritance • Single • Multiple • Multilevel • Hierarchical
  • 26.
    What is Polymorphism? Polymorphismmeans many forms The same method name can have different behaviors depending on the object Makes code more flexible and extensible
  • 27.
    Exception Handling inPython •An exception is an error that occurs during program execution •Without handling, it crashes the program •Python provides a way to catch and handle exceptions using: •try •except •Finally The try-except Block • Code that might raise an error is written inside try • Error handling code goes inside except •finally block always runs, no matter what •Used for cleanup actions (like closing files)
  • 28.
    What is aRegular Expression? A regular expression (regex) is a special pattern used to search, match, or extract data from text. Used in: Form validation (emails, phone numbers) Data extraction (scraping, logs) Text search and replace Python uses the re module to work with regex.
  • 29.
    Basic Regex Syntax PatternMeaning Example Match d Digit (0-9) 2, 98 w Word character (a-z, A-Z, 0-9, _) hello_123 . Any character except newline a.c matches abc, axc + One or more a+ matches a, aa, aaa * Zero or more lo* matches l, lo, loo [] Character set [aeiou] matches vowels ^ Start of string ^Hi matches "Hi there" $ End of string end$ matches "The end"
  • 30.
    Introduction to FileHandling File handling allows Python to create, read, write, and delete files. It is useful for: • Storing data permanently • Logging • Reading configuration or data files • Built-in functions: • open(), read(), write(), close()
  • 31.
    File Modes: Mode Description 'r'Read (default) 'w' Write (overwrite) 'a' Append 'r+' Read and write
  • 32.
    Reading and Writinga File # Writing to a file with open("demo.txt", "w") as f: f.write("Hello, Python!nFile handling is easy.") # Reading the file with open("demo.txt", "r") as f: content = f.read() print(content)
  • 33.
    Appending and ReadingLines # Appending new data with open("demo.txt", "a") as f: f.write("nThis is a new line.") # Reading line by line with open("demo.txt", "r") as f: for line in f: print(line.strip())
  • 34.
  • 35.
    What is WebScraping? Web scraping is the process of automatically extracting data from websites. It helps collect information from websites in a structured format. Often used in data analysis, market research, price monitoring, and more.
  • 36.
    Why Use WebScraping? •Automates data collection. •Saves time and reduces manual work. •Useful when APIs are unavailable. •Enables large-scale data extraction.
  • 37.
    Common Use Cases •Pricecomparison sites •News aggregation •Social media sentiment analysis •Job listing aggregators •Real estate market analysis
  • 38.
    Web Scraping Tools BeautifulSoup(Python) Scrapy (Python) Selenium (Browser automation) Puppeteer (Node.js) Requests (Python library for making HTTP requests)
  • 39.
    Introducing BeautifulSoup • APython library used to extract data from HTML and XML files. • Parses the page and creates a parse tree for easy data extraction. • Often used with requests library for fetching web pages
  • 40.
    Installing BeautifulSoup pip installbeautifulsoup4 pip install requests
  • 41.
    Simple Web ScrapingExample import requests from bs4 import BeautifulSoup url = "https://example.com" response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') title = soup.title.text print("Page Title:", title)
  • 42.
    Features of BeautifulSoup •Simpleand Pythonic syntax. •Powerful tree traversal and searching. •Supports multiple parsers (like html.parser, lxml, etc.). •Easy to integrate with other Python libraries.
  • 43.
    www.docketrun.com Confidential and Proprietary.Copyright (c) by DocketRun Tech Pvt Ltd. All Rights Reserved All images are actual or prototype DocketRun products Email ajay@docketrun.com Contact: +91-9449034387 / +91-9353412662 Website www.doketrun.com Address DocketRun Tech Pvt. Ltd. Hubballi, Karnataka - 580030, India