SlideShare a Scribd company logo
Python Tutorial
http://www.pythontraininginbangalore.in Mob : 9513332301 / 02 / 03
Architecture
Programming Language: Python
Interface: PuLP
Optimization Solvers: GLPK, CPLEX, COIN, etc.
Python Syllabus
 Introduction
 Why do we need Python?
 Program structure
 Execution steps
 Interactive Shell
 Executable or script files.
 User Interface or IDE
 Memory management and Garbage collections
 Object creation and deletion
 Object properties
 Data Types and Operations
 Numbers
 Strings
 List
 Tuple
 Dictionary
 Other Core Types
Python Syllabus
 Statements and Syntax
 Assignments, Expressions and prints
 If tests and Syntax Rules
 While and For Loops
 Iterations and Comprehensions
 File Operations and Functions
 Opening a file
 Using Files
 Other File tools
 Function definition and call
 Function Scope
 Arguments
 Function Objects
 Anonymous Functions
 Modules and Packages
 Module Creations and Usage
 Module Search Path
 Module Vs. Script
 Package Creation and Importing
Python Syllabus
 Classes and Exceptional Handling
 Classes and instances
 Classes method calls
 Inheritance and Compositions
 Static and Class Methods
 Bound and Unbound Methods
 Operator Overloading
 Polymorphism
 Default Exception Handler
 Catching Exceptions
 Raise an exception
 User defined exception
 Advanced Concepts
 Decorators
 Generators
 Iterators
 Co-routines
 Standard Library Modules
 References
 Excerces
 Roadmap with Python
Python

Python is a programming language.
Python runs on Windows, Linux/Unix, Mac OS X.
Python is free to use.


Python: Features

High-level data structures

Ex: list, tuple, dictionary

Object-oriented Interpreter
Standard library & Third party modules



Ex: pulp, numpy, matplotlib
Python: Basic Data Type

Integer (int)

Ex: 1, 2, 3, 5, 8, 13, 21

Float (float)

Ex: 3.14, 2.71828

Boolean (bool)

Ex: True, False

String (str)

Ex: 'Python', ”Sucha”
Python: High-Level Data Type

Lt(list): [ d1, d2, …, dn ]

Ex: [ 1, 3.14, True, 'a', [1], (2,3), {'B+':3.5} ]

Tuple (tuple): ( d1, d2, ..., dn, )

Ex: ( 1, 3.14, True, 'a', [1], (2,3), {'B+':3.5} )

Dictionary (dict): { k1:v1 , k2:v2 , ..., kn:vn }

Ex: { 'A':4 , 'B+':3.5 , 3:'B' }

Set (set): set([ d1, d2, ..., dn ])

Ex: set([ 4, 3.5, 'B'])
Python: Flow Control - If

If statement
if boolean:
command elif
boolean:
command
else:
command
Python: Loop - For, While

For loop
for var in sequence:
command

While loop
while boolean:
command
Python: List Comprehensions

>>>[ i for i in range(5)]
→ [ 0, 1, 2, 3, 4 ]

>>>[ i for i in range(5) if i <> 3 ]
→ [ 0, 1, 2, 4 ]

>>>[ (i, j) for i in range(3) for j in range(i) ]
→ [ (1,0), (2,0), (2,1) ]
PuLP & GLPK

PuLP is an LP modeler written in Python.
PuLP can generate LP files, and calls solvers to
solve linear problems.
Supported solvers are
GLPK, COIN, CPLEX, and GUROBI.
The GLPK (GNU Linear Programming Kit)
package is intended for solving
large-scale linear programming (LP), mixed
integer programming (MIP),
and other related problems.



PuLP: Import Module

Import module

>>>import pulp
>>>pulp.pulpTestAll()

>>>from pulp import *
>>>pulpTestAll()
Following slides assume the first import method.
PuLP: Create Decision
Variables
DV = pulp.LpVariable(name_str,
lowbound, upbound, category)
For lowbound and upbound, No bound → None .
category ∈{ pulp.LpContinuous,
pulp.LpInteger, pulp.LpBinary }
Ex: x ∈[0, ∞)
x = pulp.LpVariable('Var X', 0, None, pulp.LpContinuous)



PuLP: Formulate Problem
 PB = pulp.LpProblem(name_str, sense) sense
∈{ pulp.LpMinimize, pulp.LpMaximize }
 Ex: maximization problem
 prob = pulp.LpProblem('Benefit',
pulp.LpMaximize)
PuLP: Add Objective
Function
 PB += linear_function, objective_name_str linear_function is
in the form of
 c1*DV1 + c2*DV2 + … + cn*DVn
Ex: Cost: 2*DV1 – 1.5*DV2
prob += 2*x1 – 1.5*x2, 'Cost'
PuLP: Add Constraints

PB += linear_constraint , constraint_name_str
linear_constraint is in the form of
a1*DV1 + a2*DV2 + … + an*DVn == a0 or
a1*DV1 + a2*DV2 + … + an*DVn <= a0 or
a1*DV1 + a2*DV2 + … + an*DVn >= a0


Ex: Con1: 5*DV1 + 6*DV2 <= 7
prob += 5*x1 + 6*x2 <= 7, 'Con1' or
prob += 2*x1 + 6*x2 <= 7 – 3*x1, 'Con1'
PuLP: Write .lp File

PB.writeLP(filename_str)

Ex: write to Benefit.lp
prob.writeLP('Benefit.lp')
PuLP: Solve

PB.solve()
Ex: prob.solve()
// Solved by COIN solver


PB.solve(pulp.GLPK()) //Solved by GLPK solver
Ex: prob.solve(pulp.GLPK())

PuLP: Results

Check status: pulp.LpStatus[PB.status]
Ex: pulp.LpStatus[prob.status]


Optimal cost: pulp.value(PB.objective)
Ex: pulp.value(prob.objective)


Optimal solution: DV.varValue
Ex: x1.varValue
or pulp.value(x1)

Python Training
Second Floor and Third Floor,
5/3 BEML Layout,
Varathur Road,Kundalahalli Gate,
Bangalore – 560066

More Related Content

PPTX
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
PPTX
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PPTX
Introduction to the basics of Python programming (part 1)
PPT
Intro to Functions Python
ODP
James Jesus Bermas on Crash Course on Python
PPTX
Working with tf.data (TF 2)
PPTX
Introduction to TensorFlow 2 and Keras
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
Introduction to the basics of Python programming (part 1)
Intro to Functions Python
James Jesus Bermas on Crash Course on Python
Working with tf.data (TF 2)
Introduction to TensorFlow 2 and Keras
Python Functions Tutorial | Working With Functions In Python | Python Trainin...

What's hot (20)

PDF
Natural language processing open seminar For Tensorflow usage
PDF
Python Interview Questions And Answers
PPTX
H2 o berkeleydltf
PDF
Python basic
PPTX
Introduction to Deep Learning, Keras, and Tensorflow
PDF
Python for Dummies
PPTX
Whiteboarding Coding Challenges in Python
PPTX
Coding in Kotlin with Arrow NIDC 2018
PPTX
Introduction to TensorFlow 2
DOCX
Python interview questions and answers
PPTX
The Arrow Library in Kotlin
PPTX
Python advance
PPT
Python ppt
PDF
Biopython: Overview, State of the Art and Outlook
PPTX
Basics of Python programming (part 2)
PPTX
Performance
PPTX
Python basics
PPTX
FUNDAMENTALS OF PYTHON LANGUAGE
PPT
python.ppt
PPTX
Programming in Python
Natural language processing open seminar For Tensorflow usage
Python Interview Questions And Answers
H2 o berkeleydltf
Python basic
Introduction to Deep Learning, Keras, and Tensorflow
Python for Dummies
Whiteboarding Coding Challenges in Python
Coding in Kotlin with Arrow NIDC 2018
Introduction to TensorFlow 2
Python interview questions and answers
The Arrow Library in Kotlin
Python advance
Python ppt
Biopython: Overview, State of the Art and Outlook
Basics of Python programming (part 2)
Performance
Python basics
FUNDAMENTALS OF PYTHON LANGUAGE
python.ppt
Programming in Python
Ad

Similar to Python Training Tutorial for Frreshers (20)

PDF
Tutorial: Python, PuLP and GLPK
PDF
Python Viva Interview Questions PDF By ScholarHat
PPTX
Python 3.pptx
PPTX
Introduction to the basics of Python programming (part 3)
PDF
Python For Scientists
PPT
Phyton Learning extracts
PDF
CPPDS Slide.pdf
PPTX
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
PPTX
Introduction to learn and Python Interpreter
PPT
Python for Engineers and Architects Stud
PPTX
Python Workshop - Learn Python the Hard Way
PPTX
Python Interview Questions | Python Interview Questions And Answers | Python ...
PDF
Python overview
PDF
Porting to Python 3
PPT
Python Programming Introduction demo.ppt
PDF
Python Interview Questions PDF By ScholarHat.pdf
PDF
XII CS QUESTION BANK FOR BRIGHT STUDENTS CHAPTER WISE SET-II.pdf
PDF
class 12 computer science pdf of class e
PDF
Python_Fundamentals_for_Everyone_Usefull
PPTX
1P13 Python Review Session Covering various Topics
Tutorial: Python, PuLP and GLPK
Python Viva Interview Questions PDF By ScholarHat
Python 3.pptx
Introduction to the basics of Python programming (part 3)
Python For Scientists
Phyton Learning extracts
CPPDS Slide.pdf
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to learn and Python Interpreter
Python for Engineers and Architects Stud
Python Workshop - Learn Python the Hard Way
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python overview
Porting to Python 3
Python Programming Introduction demo.ppt
Python Interview Questions PDF By ScholarHat.pdf
XII CS QUESTION BANK FOR BRIGHT STUDENTS CHAPTER WISE SET-II.pdf
class 12 computer science pdf of class e
Python_Fundamentals_for_Everyone_Usefull
1P13 Python Review Session Covering various Topics
Ad

More from rajkamaltibacademy (17)

PPT
Corejava Training in Bangalore Tutorial
PPT
Informatica Training Tutorial
PPT
AWS Training Tutorial for Freshers
PPT
.Net Training Tutorial
PPT
CCNA Training Tutorial in bangaore
PPT
Django Training Tutorial in Bangalore
PPT
Oracle Training Tutorial for Beginners
PPT
Mongodb Training Tutorial in Bangalore
PPTX
Angular Tutorial Freshers and Experienced
PPTX
Python Tutorial for Beginner
PPTX
Teradata Tutorial for Beginners
PPT
Best Core Java Training In Bangalore
PPTX
R Programming Tutorial for Beginners - -TIB Academy
PPTX
Selenium tutorial to Beginners
PPTX
Angularjs Tutorial for Beginners
PPTX
Hadoop Training Tutorial for Freshers
PPTX
Python Tutorial for Beginner
Corejava Training in Bangalore Tutorial
Informatica Training Tutorial
AWS Training Tutorial for Freshers
.Net Training Tutorial
CCNA Training Tutorial in bangaore
Django Training Tutorial in Bangalore
Oracle Training Tutorial for Beginners
Mongodb Training Tutorial in Bangalore
Angular Tutorial Freshers and Experienced
Python Tutorial for Beginner
Teradata Tutorial for Beginners
Best Core Java Training In Bangalore
R Programming Tutorial for Beginners - -TIB Academy
Selenium tutorial to Beginners
Angularjs Tutorial for Beginners
Hadoop Training Tutorial for Freshers
Python Tutorial for Beginner

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
master seminar digital applications in india
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
RMMM.pdf make it easy to upload and study
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Lesson notes of climatology university.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
102 student loan defaulters named and shamed – Is someone you know on the list?
Sports Quiz easy sports quiz sports quiz
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Supply Chain Operations Speaking Notes -ICLT Program
human mycosis Human fungal infections are called human mycosis..pptx
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O7-L3 Supply Chain Operations - ICLT Program
master seminar digital applications in india
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Types and Its function , kingdom of life
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
RMMM.pdf make it easy to upload and study
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis

Python Training Tutorial for Frreshers

  • 2. Architecture Programming Language: Python Interface: PuLP Optimization Solvers: GLPK, CPLEX, COIN, etc.
  • 3. Python Syllabus  Introduction  Why do we need Python?  Program structure  Execution steps  Interactive Shell  Executable or script files.  User Interface or IDE  Memory management and Garbage collections  Object creation and deletion  Object properties  Data Types and Operations  Numbers  Strings  List  Tuple  Dictionary  Other Core Types
  • 4. Python Syllabus  Statements and Syntax  Assignments, Expressions and prints  If tests and Syntax Rules  While and For Loops  Iterations and Comprehensions  File Operations and Functions  Opening a file  Using Files  Other File tools  Function definition and call  Function Scope  Arguments  Function Objects  Anonymous Functions  Modules and Packages  Module Creations and Usage  Module Search Path  Module Vs. Script  Package Creation and Importing
  • 5. Python Syllabus  Classes and Exceptional Handling  Classes and instances  Classes method calls  Inheritance and Compositions  Static and Class Methods  Bound and Unbound Methods  Operator Overloading  Polymorphism  Default Exception Handler  Catching Exceptions  Raise an exception  User defined exception  Advanced Concepts  Decorators  Generators  Iterators  Co-routines  Standard Library Modules  References  Excerces  Roadmap with Python
  • 6. Python  Python is a programming language. Python runs on Windows, Linux/Unix, Mac OS X. Python is free to use.  
  • 7. Python: Features  High-level data structures  Ex: list, tuple, dictionary  Object-oriented Interpreter Standard library & Third party modules    Ex: pulp, numpy, matplotlib
  • 8. Python: Basic Data Type  Integer (int)  Ex: 1, 2, 3, 5, 8, 13, 21  Float (float)  Ex: 3.14, 2.71828  Boolean (bool)  Ex: True, False  String (str)  Ex: 'Python', ”Sucha”
  • 9. Python: High-Level Data Type  Lt(list): [ d1, d2, …, dn ]  Ex: [ 1, 3.14, True, 'a', [1], (2,3), {'B+':3.5} ]  Tuple (tuple): ( d1, d2, ..., dn, )  Ex: ( 1, 3.14, True, 'a', [1], (2,3), {'B+':3.5} )  Dictionary (dict): { k1:v1 , k2:v2 , ..., kn:vn }  Ex: { 'A':4 , 'B+':3.5 , 3:'B' }  Set (set): set([ d1, d2, ..., dn ])  Ex: set([ 4, 3.5, 'B'])
  • 10. Python: Flow Control - If  If statement if boolean: command elif boolean: command else: command
  • 11. Python: Loop - For, While  For loop for var in sequence: command  While loop while boolean: command
  • 12. Python: List Comprehensions  >>>[ i for i in range(5)] → [ 0, 1, 2, 3, 4 ]  >>>[ i for i in range(5) if i <> 3 ] → [ 0, 1, 2, 4 ]  >>>[ (i, j) for i in range(3) for j in range(i) ] → [ (1,0), (2,0), (2,1) ]
  • 13. PuLP & GLPK  PuLP is an LP modeler written in Python. PuLP can generate LP files, and calls solvers to solve linear problems. Supported solvers are GLPK, COIN, CPLEX, and GUROBI. The GLPK (GNU Linear Programming Kit) package is intended for solving large-scale linear programming (LP), mixed integer programming (MIP), and other related problems.   
  • 14. PuLP: Import Module  Import module  >>>import pulp >>>pulp.pulpTestAll()  >>>from pulp import * >>>pulpTestAll() Following slides assume the first import method.
  • 15. PuLP: Create Decision Variables DV = pulp.LpVariable(name_str, lowbound, upbound, category) For lowbound and upbound, No bound → None . category ∈{ pulp.LpContinuous, pulp.LpInteger, pulp.LpBinary } Ex: x ∈[0, ∞) x = pulp.LpVariable('Var X', 0, None, pulp.LpContinuous)   
  • 16. PuLP: Formulate Problem  PB = pulp.LpProblem(name_str, sense) sense ∈{ pulp.LpMinimize, pulp.LpMaximize }  Ex: maximization problem  prob = pulp.LpProblem('Benefit', pulp.LpMaximize)
  • 17. PuLP: Add Objective Function  PB += linear_function, objective_name_str linear_function is in the form of  c1*DV1 + c2*DV2 + … + cn*DVn Ex: Cost: 2*DV1 – 1.5*DV2 prob += 2*x1 – 1.5*x2, 'Cost'
  • 18. PuLP: Add Constraints  PB += linear_constraint , constraint_name_str linear_constraint is in the form of a1*DV1 + a2*DV2 + … + an*DVn == a0 or a1*DV1 + a2*DV2 + … + an*DVn <= a0 or a1*DV1 + a2*DV2 + … + an*DVn >= a0   Ex: Con1: 5*DV1 + 6*DV2 <= 7 prob += 5*x1 + 6*x2 <= 7, 'Con1' or prob += 2*x1 + 6*x2 <= 7 – 3*x1, 'Con1'
  • 19. PuLP: Write .lp File  PB.writeLP(filename_str)  Ex: write to Benefit.lp prob.writeLP('Benefit.lp')
  • 20. PuLP: Solve  PB.solve() Ex: prob.solve() // Solved by COIN solver   PB.solve(pulp.GLPK()) //Solved by GLPK solver Ex: prob.solve(pulp.GLPK()) 
  • 21. PuLP: Results  Check status: pulp.LpStatus[PB.status] Ex: pulp.LpStatus[prob.status]   Optimal cost: pulp.value(PB.objective) Ex: pulp.value(prob.objective)   Optimal solution: DV.varValue Ex: x1.varValue or pulp.value(x1) 
  • 22. Python Training Second Floor and Third Floor, 5/3 BEML Layout, Varathur Road,Kundalahalli Gate, Bangalore – 560066