SlideShare a Scribd company logo
Python Master Class
Part 1
By Chathuranga Bandara
www.chathuranga.com
Today’s Agenda
Introduction to Python
Introduction to Flask
Python
What is Python
 really..
Multi Purpose
Object Oriented
Interpreted?
Dynamically Typed and Strong as well
Readability and We are Adults!
Features
Cross Platform
Functional Support as well
Everything is an Object
Many Implementations
Batteries Included
Who Uses Python?
Why Python?
Python master class part 1
Python master class part 1
Versions
v2.7.X
v3.X
Some Tax
. i mean Syntax..
Indentation is the Key!
Python master class part 1
Python master class part 1
Types?
Not Strongly Typed
What the f*** that means?
Let’s Discuss Python Memory Management.
What is a C type Variable?
Variable location value
a 0x3FS 101
b 0x3F9 101
unique location These values live in a fixed
size bracket hence can only
hold same sized data or an
overflow happens
When we change one value
Variable location value
a 0x3FS 110
b 0x3F9 101
Data in the memory location
get overwritten
Python has Names not Variables
names
references
objects
Name is just a label for an object
In Python you can have multiple names for a single object
What is a reference?
Name or a container pointing to an object
ie:
110
x = 110
x
+1 reference count
110
x = 110
y = 110
x
+2 reference count
y
Not sure?
also,
z = [110, 110]
110
x
y
Reference count: 4
Decrease Ref count?
110
x
reference count: 1
y
del will not delete the object but rather delete the reference to the object.
What happens when the ref count is 0?
Then it will delete the object. (what the garbage collector does in python)
Different types of objects then?
● Numbers
● Strings
● dict
● list
● classes
Because of names
Python master class part 1
Functions also can have names
Strings
Numbers
None is the new null
Lists
List Comprehension
Dictionaries
Mutable vs Immutable
Mutable : can alter
● list, dict, byte array, set
Immutable: otherwise
● Numbers, string, tuples, frozen sets
ie:
Is extremely inefficient
Much efficient
Control Flows - Conditionals
Loops
Functions
Python master class part 1
CLASSES
Python master class part 1
What is PIP?
pip is the Python package index
$ sudo apt-get install python-pip
Virtual Environment?
$ pip install virtualenv
$ cd my_project_folder
$ virtualenv name_of_the_virt
$ source name_of_the_virt/bin/activate
$ do pip sh*t
$ deactivate
Good practice!
Have a folder in root called requirements and inside that have following:
● dev.txt
● Prod.txt
Ie: dev.txt
$ pip install -r requirements/dev.txt
pip install Flask
# Import Flask library
from flask import Flask
# Initialize the app from Flask
app = Flask(__name__)
# Define a route to hello_world function
@app.route('/hello')
def hello_world():
return 'Hello World Again!'
# Run the app on http://localhost:8085
app.run(debug=True,port=8085)
python hello.py
Python master class part 1
Python master class part 1
Routing
@app.route('/')
def index():
return 'Index
Page'
@app.route('/hello')
def hello():
return 'Hello, World'
Variables?
@app.route('/user/<username>')
def show_user_profile(username):
# show the user profile for that user
return 'User %s' % username
@app.route('/post/<int:post_id>')
def show_post(post_id):
# show the post with the given id, the id is an integer
return 'Post %d' % post_id
That is sweet, what about the REST?
from flask import request
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
do_the_login()
else:
show_the_login_form()
Rendering Templates
from flask import render_template
@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
return render_template('hello.html', name=name)
Where the f**k is the template then?
<!doctype html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello, World!</h1>
{% endif %}
Request Object
from flask import request
@app.route('/login', methods=['POST', 'GET'])
def login():
error = None
if request.method == 'POST':
if valid_login(request.form['username'],
request.form['password']):
return log_the_user_in(request.form['username'])
else:
error = 'Invalid username/password'
# the code below is executed if the request method
# was GET or the credentials were invalid
return render_template('login.html', error=error)
sessions
from flask import Flask, session, redirect, url_for, escape, request
app = Flask(__name__)
@app.route('/')
def index():
if 'username' in session:
return 'Logged in as %s' % escape(session['username'])
return 'You are not logged in'
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
session['username'] = request.form['username']
return redirect(url_for('index'))
return ''' <form action="" method="post">
<p><input type=text name=username>
<p><input type=submit value=Login>
</form>
'''
@app.route('/logout')
def logout():
# remove the username from the session if it's there
session.pop('username', None)
return redirect(url_for('index'))
# set the secret key. keep this really secret:
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
That’s all for today Folks!

More Related Content

What's hot (20)

PPTX
Introduction Ă  Python
Abdoulaye Dieng
 
PPTX
Chapitre1: Langage Python
Aziz Darouichi
 
PPTX
Pemrograman Mobile - JetPack Compose1.pptx
Fajar Baskoro
 
PDF
From object oriented to functional domain modeling
Mario Fusco
 
PDF
Initiation au langage python
Sarah
 
PPTX
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
PDF
Data mining - Classification - arbres de décision
Mohamed Heny SELMI
 
PPTX
Python.pptx
Jaouad Rachek
 
DOCX
Data Structure Project File
Deyvessh kumar
 
PDF
Python introduction
Jignesh Kariya
 
PDF
Chap2 Les conteneurs en python
Mariem ZAOUALI
 
PPTX
What Are Coroutines In Kotlin?
Simplilearn
 
PDF
Cours langage-c
Ahmed MSAFRI
 
PDF
Python avancé : Lecture et écriture de fichiers
ECAM Brussels Engineering School
 
PDF
Cours python avancé
pierrepo
 
PPTX
Langage C#
Jean-Baptiste Vigneron
 
PPT
Projet BI - 1 - Analyse des besoins
Jean-Marc Dupont
 
PPT
Java tutorial PPT
Intelligo Technologies
 
PDF
Introduction to JCR
David Nuescheler
 
PPTX
An introduction to Jupyter notebooks and the Noteable service
Jisc
 
Introduction Ă  Python
Abdoulaye Dieng
 
Chapitre1: Langage Python
Aziz Darouichi
 
Pemrograman Mobile - JetPack Compose1.pptx
Fajar Baskoro
 
From object oriented to functional domain modeling
Mario Fusco
 
Initiation au langage python
Sarah
 
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
Data mining - Classification - arbres de décision
Mohamed Heny SELMI
 
Python.pptx
Jaouad Rachek
 
Data Structure Project File
Deyvessh kumar
 
Python introduction
Jignesh Kariya
 
Chap2 Les conteneurs en python
Mariem ZAOUALI
 
What Are Coroutines In Kotlin?
Simplilearn
 
Cours langage-c
Ahmed MSAFRI
 
Python avancé : Lecture et écriture de fichiers
ECAM Brussels Engineering School
 
Cours python avancé
pierrepo
 
Projet BI - 1 - Analyse des besoins
Jean-Marc Dupont
 
Java tutorial PPT
Intelligo Technologies
 
Introduction to JCR
David Nuescheler
 
An introduction to Jupyter notebooks and the Noteable service
Jisc
 

Viewers also liked (20)

PDF
Introduction to Python for Data Science
Arc & Codementor
 
PPTX
Python-The programming Language
Rohan Gupta
 
PPT
Introduction to Python - Part Three
amiable_indian
 
PPT
Introduction to Python - Part Two
amiable_indian
 
PDF
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang
 
PPTX
Introduction to Advanced Javascript
Collaboration Technologies
 
PDF
Analysis of Fatal Utah Avalanches with Python. From Scraping, Analysis, to In...
Matt Harrison
 
PDF
Python - Lecture 1
Ravi Kiran Khareedi
 
PDF
Java OOP Programming language (Part 1) - Introduction to Java
OUM SAOKOSAL
 
PDF
Meetup Python Nantes - les tests en python
Arthur Lutz
 
PPT
Operator Overloading
Sardar Alam
 
PDF
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
PDF
Installing Python on Mac
Wei-Wen Hsu
 
PDF
Python for All
Pragya Goyal
 
PDF
Introduction to python
Yi-Fan Chu
 
PDF
Lesson1 python an introduction
Arulalan T
 
DOCX
Introduction to Python - Running Notes
RajKumar Rampelli
 
PDF
Introduction to facebook java script sdk
Yi-Fan Chu
 
PDF
Introduction to facebook javascript sdk
Yi-Fan Chu
 
PPTX
Lec02 structures (2)
Khuder Altangerel
 
Introduction to Python for Data Science
Arc & Codementor
 
Python-The programming Language
Rohan Gupta
 
Introduction to Python - Part Three
amiable_indian
 
Introduction to Python - Part Two
amiable_indian
 
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang
 
Introduction to Advanced Javascript
Collaboration Technologies
 
Analysis of Fatal Utah Avalanches with Python. From Scraping, Analysis, to In...
Matt Harrison
 
Python - Lecture 1
Ravi Kiran Khareedi
 
Java OOP Programming language (Part 1) - Introduction to Java
OUM SAOKOSAL
 
Meetup Python Nantes - les tests en python
Arthur Lutz
 
Operator Overloading
Sardar Alam
 
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
Installing Python on Mac
Wei-Wen Hsu
 
Python for All
Pragya Goyal
 
Introduction to python
Yi-Fan Chu
 
Lesson1 python an introduction
Arulalan T
 
Introduction to Python - Running Notes
RajKumar Rampelli
 
Introduction to facebook java script sdk
Yi-Fan Chu
 
Introduction to facebook javascript sdk
Yi-Fan Chu
 
Lec02 structures (2)
Khuder Altangerel
 
Ad

Similar to Python master class part 1 (20)

PPTX
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Sian Lerk Lau
 
PPTX
PyCourse - Self driving python course
Eran Shlomo
 
PPTX
trabalho ingles instrumental prof Anderson.pptx
VICENTEPAULOSADASILV
 
PDF
Introduction to python 3 2nd round
Youhei Sakurai
 
PPTX
Application development with Python - Desktop application
Bao Long Nguyen Dang
 
PPTX
Programming Lecture 2nd - Flask and Heroku in Python -
Naoki Watanabe
 
PDF
Introduction to python 3
Youhei Sakurai
 
PDF
Flask Introduction - Python Meetup
Areski Belaid
 
PPTX
Flask
Mamta Kumari
 
PDF
Python For All | Software Professionals, QA & DevOps professionals
Nilesh Sutar
 
PDF
Lecture1_cis4930.pdf
zertash1
 
PDF
Introduction to python
Mohammed Rafi
 
PDF
Mastering the Interview: 50 Common Interview Questions Demystified
MalcolmDupri
 
PDF
What is python
EU Edge
 
PPT
Python basics to advanced in on ppt is available
nexasbravo2000sep
 
PDF
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
CodeCore
 
PDF
Flask for cs students
Jennifer Rubinovitz
 
PDF
Free Python Notes PDF - Python Crash Course
Amend Ed Tech
 
PPTX
intro to python.pptx
UpasnaSharma37
 
PPTX
3-Tut2_Interfacing_Sensors_RPioT.pptx good reference
ssuser0b643d
 
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Sian Lerk Lau
 
PyCourse - Self driving python course
Eran Shlomo
 
trabalho ingles instrumental prof Anderson.pptx
VICENTEPAULOSADASILV
 
Introduction to python 3 2nd round
Youhei Sakurai
 
Application development with Python - Desktop application
Bao Long Nguyen Dang
 
Programming Lecture 2nd - Flask and Heroku in Python -
Naoki Watanabe
 
Introduction to python 3
Youhei Sakurai
 
Flask Introduction - Python Meetup
Areski Belaid
 
Flask
Mamta Kumari
 
Python For All | Software Professionals, QA & DevOps professionals
Nilesh Sutar
 
Lecture1_cis4930.pdf
zertash1
 
Introduction to python
Mohammed Rafi
 
Mastering the Interview: 50 Common Interview Questions Demystified
MalcolmDupri
 
What is python
EU Edge
 
Python basics to advanced in on ppt is available
nexasbravo2000sep
 
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
CodeCore
 
Flask for cs students
Jennifer Rubinovitz
 
Free Python Notes PDF - Python Crash Course
Amend Ed Tech
 
intro to python.pptx
UpasnaSharma37
 
3-Tut2_Interfacing_Sensors_RPioT.pptx good reference
ssuser0b643d
 
Ad

More from Chathuranga Bandara (9)

PDF
What is F# and why should we give a f#ck?
Chathuranga Bandara
 
PPTX
Is your app secure
Chathuranga Bandara
 
PDF
Agile negotiations
Chathuranga Bandara
 
PDF
Python master class 3
Chathuranga Bandara
 
PDF
Python master class 2
Chathuranga Bandara
 
PDF
Introduction to Celery
Chathuranga Bandara
 
PDF
Introduction to Cloud Computing (New)
Chathuranga Bandara
 
PDF
Introduction to Cloud Computing
Chathuranga Bandara
 
PPTX
Responsive Vs Dedicated: Insight into Mobile Web
Chathuranga Bandara
 
What is F# and why should we give a f#ck?
Chathuranga Bandara
 
Is your app secure
Chathuranga Bandara
 
Agile negotiations
Chathuranga Bandara
 
Python master class 3
Chathuranga Bandara
 
Python master class 2
Chathuranga Bandara
 
Introduction to Celery
Chathuranga Bandara
 
Introduction to Cloud Computing (New)
Chathuranga Bandara
 
Introduction to Cloud Computing
Chathuranga Bandara
 
Responsive Vs Dedicated: Insight into Mobile Web
Chathuranga Bandara
 

Recently uploaded (20)

PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Human Resources Information System (HRIS)
Amity University, Patna
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 

Python master class part 1