SlideShare a Scribd company logo
The Awesome
File handling, Exceptions, Standard libraries,
debugger, magic functions, lambda forms, assert,
decorators, memory management.
Part-5
Summary of Previous Parts
We are done with discussing the Data types in python, Basic Data structures,
their syntaxes and their usage, inputs, Iterators/generators, Operators, Control
flow, Branches etc.
In the last presentation we have covered, Modules, Functions, Class, Metaclass,
OOPs Concepts.
We will move forward with lot many things,
I hope you enjoy the show.
2
File Handling
3 different modes in file handling. ‘r’, ‘w’, ‘a’.
‘b’ is file handling mode for binary, that you can append with any type and
change at binary level.
Open has to be followed by close.
with open doesn’t need any close.
Be careful if file is opened in write mode it removes everything that is already
present.
3
Exceptions
Syntax
4
● One try can have multiple excepts.
● Try can have else which will get executed
when no exception occurs.
● finally can be used with try which will
always get executed irrespective of any
situation.
● We can manually raise exception if we
want.
Standard Libraries
There is a hell lot of standard libraries present in python.
Refer the link to read about all standard libraries.
https://docs.python.org/2/library/
5
Debugger & Magic Functions
Python debugger is a very useful and
important tool in development.
There are many functions present in
debugger.
set_trace is the main function to debug the
code flow.
6
Magic functions are special methods that
you can define to add "magic" to your
classes.
They're always surrounded by double
underscores (e.g. __init__ or __lt__).
They're also not as well documented as they
need to be.
All of the magic methods for Python appear
in the same section in the Python docs,
but they're scattered about and only
loosely organized.
Lambda
These functions are throw-away functions, i.e.
they are just needed where they have been
created.
Lambda functions are mainly used in
combination with the functions filter(), map()
and reduce().
The lambda feature was added to Python due to
the demand from Lisp programmers
7
An anonymous functions
Map, Reduce, Filter
Using map and data set can be mapped to
a function like below.
Syntax is
map(aFunction, aSequence)
8
Reduce is like map but it uses lambda to reduce
the data to a value instead of mapping.
assert
Assert is always True.
Any value other than True will break the assert.
9
Decorators
Decorators allow you to make simple
modifications to callable objects like functions,
methods, or classes. We shall deal with
functions for this tutorial.
10
Memory Management
Memory management in Python involves a private heap containing all Python objects and data
structures. Interpreter takes care of Python heap and that the programmer has no access to
it.
The allocation of heap space for Python objects is done by Python memory manager. The core
API of Python provides some tools for the programmer to code reliable and more robust
program.
Python also has a build-in garbage collector which recycles all the unused memory. When an
object is no longer referenced by the program, the heap space it occupies can be freed.
The garbage collector determines objects which are no longer referenced by the sprogram
frees the occupied memory and make it available to the heap space.
The gc module defines functions to enable /disable garbage collector:
11
ThanksStay Tuned for the next part. Enjoy !!
12

More Related Content

What's hot (20)

PDF
Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov
 
DOCX
Python Interview Questions For Experienced
zynofustechnology
 
PDF
Python revision tour i
Mr. Vikram Singh Slathia
 
DOCX
Python interview questions and answers
RojaPriya
 
PPTX
Python Session - 5
AnirudhaGaikwad4
 
PPTX
Python second ppt
RaginiJain21
 
DOCX
Notes on c++
Selvam Edwin
 
PDF
Python interview questions and answers
kavinilavuG
 
PDF
Python Advanced – Building on the foundation
Kevlin Henney
 
DOCX
Python interview questions for experience
MYTHILIKRISHNAN4
 
PPSX
Programming with Python
Rasan Samarasinghe
 
DOCX
Python Interview Questions For Freshers
zynofustechnology
 
PPTX
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
PPTX
Python Session - 4
AnirudhaGaikwad4
 
PPTX
Programming in C sesion 2
Prerna Sharma
 
PPTX
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
PPTX
Chapter 9 python fundamentals
Praveen M Jigajinni
 
PDF
Programming in C Session 1
Prerna Sharma
 
PPTX
Python Session - 2
AnirudhaGaikwad4
 
PDF
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov
 
Python Interview Questions For Experienced
zynofustechnology
 
Python revision tour i
Mr. Vikram Singh Slathia
 
Python interview questions and answers
RojaPriya
 
Python Session - 5
AnirudhaGaikwad4
 
Python second ppt
RaginiJain21
 
Notes on c++
Selvam Edwin
 
Python interview questions and answers
kavinilavuG
 
Python Advanced – Building on the foundation
Kevlin Henney
 
Python interview questions for experience
MYTHILIKRISHNAN4
 
Programming with Python
Rasan Samarasinghe
 
Python Interview Questions For Freshers
zynofustechnology
 
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
Python Session - 4
AnirudhaGaikwad4
 
Programming in C sesion 2
Prerna Sharma
 
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Chapter 9 python fundamentals
Praveen M Jigajinni
 
Programming in C Session 1
Prerna Sharma
 
Python Session - 2
AnirudhaGaikwad4
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 

Viewers also liked (7)

PDF
8 grejer som storföretag kan lära av startups
Idea Hunt
 
PPTX
Grunt och gulp
Lars Gunther
 
PDF
I huvudet på en cloudarkitekt | cloudcache.io
welovecloud
 
PDF
ASAS 2013 - Agility and the essence of software architecture
Avisi B.V.
 
PPTX
Getting started with ES6 : Future of javascript
Mohd Saeed
 
PPTX
Support Vector Machine without tears
Ankit Sharma
 
PDF
Linear regression without tears
Ankit Sharma
 
8 grejer som storföretag kan lära av startups
Idea Hunt
 
Grunt och gulp
Lars Gunther
 
I huvudet på en cloudarkitekt | cloudcache.io
welovecloud
 
ASAS 2013 - Agility and the essence of software architecture
Avisi B.V.
 
Getting started with ES6 : Future of javascript
Mohd Saeed
 
Support Vector Machine without tears
Ankit Sharma
 
Linear regression without tears
Ankit Sharma
 
Ad

Similar to The Awesome Python Class Part-5 (20)

PDF
First Steps in Python Programming
Dozie Agbo
 
PPTX
Summer Training Project On Python Programming
KAUSHAL KUMAR JHA
 
PPTX
Intro to python
Mohamed Essam
 
PPTX
Basic of python for data analysis
Pramod Toraskar
 
PPTX
python programming ppt-230111072927-1c7002a5.pptx
pprince22982
 
PPTX
PYTHON PPT.pptx
AbhishekMourya36
 
PDF
Python Programming Course Presentations
DreamerInfotech
 
PDF
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
Tutort Academy
 
PPTX
Python and You Series
Karthik Prakash
 
PDF
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
 
PDF
python interview prep question , 52 questions
gokul174578
 
PPTX
Python-FileHandling.pptx
Karudaiyar Ganapathy
 
PPTX
Introduction_to_Python.pptx
Vinay Chowdary
 
PDF
Python and Zope: An introduction (May 2004)
Kiran Jonnalagadda
 
PDF
🐍⚡ “Python Panache: Code Like a Pro, Not a Programmer!”
yashikanigam1
 
PDF
Top Most Python Interview Questions.pdf
Datacademy.ai
 
DOCX
These questions will be a bit advanced level 2
sadhana312471
 
DOCX
Python Course.docx
AdnanAhmad57885
 
PPTX
Functions in Python
Shakti Singh Rathore
 
PPTX
MODULE 1.pptx
KPDDRAVIDIAN
 
First Steps in Python Programming
Dozie Agbo
 
Summer Training Project On Python Programming
KAUSHAL KUMAR JHA
 
Intro to python
Mohamed Essam
 
Basic of python for data analysis
Pramod Toraskar
 
python programming ppt-230111072927-1c7002a5.pptx
pprince22982
 
PYTHON PPT.pptx
AbhishekMourya36
 
Python Programming Course Presentations
DreamerInfotech
 
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
Tutort Academy
 
Python and You Series
Karthik Prakash
 
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
 
python interview prep question , 52 questions
gokul174578
 
Python-FileHandling.pptx
Karudaiyar Ganapathy
 
Introduction_to_Python.pptx
Vinay Chowdary
 
Python and Zope: An introduction (May 2004)
Kiran Jonnalagadda
 
🐍⚡ “Python Panache: Code Like a Pro, Not a Programmer!”
yashikanigam1
 
Top Most Python Interview Questions.pdf
Datacademy.ai
 
These questions will be a bit advanced level 2
sadhana312471
 
Python Course.docx
AdnanAhmad57885
 
Functions in Python
Shakti Singh Rathore
 
MODULE 1.pptx
KPDDRAVIDIAN
 
Ad

Recently uploaded (20)

PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPTX
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
MRRS Strength and Durability of Concrete
CivilMythili
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 

The Awesome Python Class Part-5

  • 1. The Awesome File handling, Exceptions, Standard libraries, debugger, magic functions, lambda forms, assert, decorators, memory management. Part-5
  • 2. Summary of Previous Parts We are done with discussing the Data types in python, Basic Data structures, their syntaxes and their usage, inputs, Iterators/generators, Operators, Control flow, Branches etc. In the last presentation we have covered, Modules, Functions, Class, Metaclass, OOPs Concepts. We will move forward with lot many things, I hope you enjoy the show. 2
  • 3. File Handling 3 different modes in file handling. ‘r’, ‘w’, ‘a’. ‘b’ is file handling mode for binary, that you can append with any type and change at binary level. Open has to be followed by close. with open doesn’t need any close. Be careful if file is opened in write mode it removes everything that is already present. 3
  • 4. Exceptions Syntax 4 ● One try can have multiple excepts. ● Try can have else which will get executed when no exception occurs. ● finally can be used with try which will always get executed irrespective of any situation. ● We can manually raise exception if we want.
  • 5. Standard Libraries There is a hell lot of standard libraries present in python. Refer the link to read about all standard libraries. https://docs.python.org/2/library/ 5
  • 6. Debugger & Magic Functions Python debugger is a very useful and important tool in development. There are many functions present in debugger. set_trace is the main function to debug the code flow. 6 Magic functions are special methods that you can define to add "magic" to your classes. They're always surrounded by double underscores (e.g. __init__ or __lt__). They're also not as well documented as they need to be. All of the magic methods for Python appear in the same section in the Python docs, but they're scattered about and only loosely organized.
  • 7. Lambda These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce(). The lambda feature was added to Python due to the demand from Lisp programmers 7 An anonymous functions
  • 8. Map, Reduce, Filter Using map and data set can be mapped to a function like below. Syntax is map(aFunction, aSequence) 8 Reduce is like map but it uses lambda to reduce the data to a value instead of mapping.
  • 9. assert Assert is always True. Any value other than True will break the assert. 9
  • 10. Decorators Decorators allow you to make simple modifications to callable objects like functions, methods, or classes. We shall deal with functions for this tutorial. 10
  • 11. Memory Management Memory management in Python involves a private heap containing all Python objects and data structures. Interpreter takes care of Python heap and that the programmer has no access to it. The allocation of heap space for Python objects is done by Python memory manager. The core API of Python provides some tools for the programmer to code reliable and more robust program. Python also has a build-in garbage collector which recycles all the unused memory. When an object is no longer referenced by the program, the heap space it occupies can be freed. The garbage collector determines objects which are no longer referenced by the sprogram frees the occupied memory and make it available to the heap space. The gc module defines functions to enable /disable garbage collector: 11
  • 12. ThanksStay Tuned for the next part. Enjoy !! 12