SlideShare a Scribd company logo
Copyright Intellipaat. All rights reserved.
Closures in Python
Copyright Intellipaat. All rights reserved.
Agenda
03 Example
01 Prerequisite
04 Use case
02 Definition
Copyright Intellipaat. All rights reserved.
Prerequisite
Copyright Intellipaat. All rights reserved.
Prerequisite
First class function
First class functions allows us to treat functions as any other objects, so that we can use them to:
 pass as an argument to another function
 return the function from another function
 assign the function to another variable
Nested function
Python supports the concept of a "nested function" or "inner function", which is simply a function
defined inside another function.
Note: Not to be confused with recursive functions
Copyright Intellipaat. All rights reserved.
Definition
Copyright Intellipaat. All rights reserved.
Definition
Closure is an inner function that remembers and has access to the variables in the local scope in which
it was created even after the outer function has finished executing.
A closure closes over their free variable from their environment
Copyright Intellipaat. All rights reserved.
Example
Copyright Intellipaat. All rights reserved.
Use case
Copyright Intellipaat. All rights reserved.
Use case
 To replace the unnecessary use of class: Suppose you have a class that contains just one method
besides the __init__ method. In such cases, it is better to use a closure instead of a class.
 To avoid the use of the global scope: If you have global variables which only one function in your
program will use, think closure. Define the variables in the outer function and use them in the inner
function.
 To implement data hiding: The only way to access the enclosed function is by calling the enclosing
function. There is no way to access the inner function directly.
 To remember a function environment even after it completes its execution: You can then access the
variables of this environment later in your program.
Copyright Intellipaat. All rights reserved.
• Further Learning..
Copyright Intellipaat. All rights reserved.
Further Learning
Copyright Intellipaat. All rights reserved.
India: +91-7022374614
US: 1-800-216-8930 (TOLL FREE)
support@intellipaat.com
24/7 Chat with Our Course Advisor

More Related Content

What's hot

python Function
python Function python Function
python Function
Ronak Rathi
 
Advance python
Advance pythonAdvance python
Advance python
pulkit agrawal
 
Python The basics
Python   The basicsPython   The basics
Python The basics
Bobby Murugesan
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Pointers
PointersPointers
Pointers
Joy Forerver
 
Python advance
Python advancePython advance
Python advance
Deepak Chandella
 
Intro to Functions Python
Intro to Functions PythonIntro to Functions Python
Intro to Functions Python
primeteacher32
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
ShwetaAggarwal56
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Shakti Singh Rathore
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
Knoldus Inc.
 
Scala functions
Scala functionsScala functions
Scala functions
Knoldus Inc.
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Kamal Acharya
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
Knoldus Inc.
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Maulik Borsaniya
 
Python modules
Python modulesPython modules
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Pointers
PointersPointers
Pointers
Lp Singh
 
Function overloading
Function overloadingFunction overloading
Function overloading
Sudeshna Biswas
 

What's hot (20)

python Function
python Function python Function
python Function
 
Advance python
Advance pythonAdvance python
Advance python
 
Python The basics
Python   The basicsPython   The basics
Python The basics
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Python programming
Python  programmingPython  programming
Python programming
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Pointers
PointersPointers
Pointers
 
Python advance
Python advancePython advance
Python advance
 
Intro to Functions Python
Intro to Functions PythonIntro to Functions Python
Intro to Functions Python
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Scala functions
Scala functionsScala functions
Scala functions
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
 
Python modules
Python modulesPython modules
Python modules
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
 
Pointers
PointersPointers
Pointers
 
Function overloading
Function overloadingFunction overloading
Function overloading
 

Similar to Python Closures Explained | What are Closures in Python | Python Closures

python interview prep question , 52 questions
python interview prep question , 52 questionspython interview prep question , 52 questions
python interview prep question , 52 questions
gokul174578
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
Srinivas Narasegouda
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
satish reddy
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
satish reddy
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
Shipra Swati
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
melbournepatterns
 
Latest C Interview Questions and Answers
Latest C Interview Questions and AnswersLatest C Interview Questions and Answers
Latest C Interview Questions and Answers
DaisyWatson5
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
Python-Encapsulation.pptx
Python-Encapsulation.pptxPython-Encapsulation.pptx
Python-Encapsulation.pptx
Karudaiyar Ganapathy
 
Php, mysq lpart3
Php, mysq lpart3Php, mysq lpart3
Php, mysq lpart3
Subhasis Nayak
 
My c++
My c++My c++
My c++
snathick
 
The Awesome Python Class Part-4
The Awesome Python Class Part-4The Awesome Python Class Part-4
The Awesome Python Class Part-4
Binay Kumar Ray
 
Function overloading
Function overloadingFunction overloading
Function overloading
Prof. Dr. K. Adisesha
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
Kuntal Bhowmick
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
Soba Arjun
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
colleges
 
Questions of java
Questions of javaQuestions of java
Questions of java
Waseem Wasi
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 

Similar to Python Closures Explained | What are Closures in Python | Python Closures (20)

python interview prep question , 52 questions
python interview prep question , 52 questionspython interview prep question , 52 questions
python interview prep question , 52 questions
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Latest C Interview Questions and Answers
Latest C Interview Questions and AnswersLatest C Interview Questions and Answers
Latest C Interview Questions and Answers
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Python-Encapsulation.pptx
Python-Encapsulation.pptxPython-Encapsulation.pptx
Python-Encapsulation.pptx
 
Php, mysq lpart3
Php, mysq lpart3Php, mysq lpart3
Php, mysq lpart3
 
My c++
My c++My c++
My c++
 
The Awesome Python Class Part-4
The Awesome Python Class Part-4The Awesome Python Class Part-4
The Awesome Python Class Part-4
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Questions of java
Questions of javaQuestions of java
Questions of java
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
 

More from Intellipaat

What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...
What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...
What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...
Intellipaat
 
How to Become Business Intelligence Analyst?
How to Become Business Intelligence Analyst?How to Become Business Intelligence Analyst?
How to Become Business Intelligence Analyst?
Intellipaat
 
CCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 Exam
CCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 ExamCCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 Exam
CCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 Exam
Intellipaat
 
Top 5 In-demand technologies to Learn in 2020
Top 5 In-demand technologies to Learn in 2020Top 5 In-demand technologies to Learn in 2020
Top 5 In-demand technologies to Learn in 2020
Intellipaat
 
Top 5 Data Science Certifications
Top 5 Data Science CertificationsTop 5 Data Science Certifications
Top 5 Data Science Certifications
Intellipaat
 
Different Roles in Machine Learning Career
Different Roles in Machine Learning CareerDifferent Roles in Machine Learning Career
Different Roles in Machine Learning Career
Intellipaat
 

More from Intellipaat (6)

What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...
What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...
What is PodCast Marketing | PodCast For Business | How to Start a Podcast | I...
 
How to Become Business Intelligence Analyst?
How to Become Business Intelligence Analyst?How to Become Business Intelligence Analyst?
How to Become Business Intelligence Analyst?
 
CCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 Exam
CCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 ExamCCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 Exam
CCA 175 - Hadoop & Spark Developer Certification | Cloudera CCA 175 Exam
 
Top 5 In-demand technologies to Learn in 2020
Top 5 In-demand technologies to Learn in 2020Top 5 In-demand technologies to Learn in 2020
Top 5 In-demand technologies to Learn in 2020
 
Top 5 Data Science Certifications
Top 5 Data Science CertificationsTop 5 Data Science Certifications
Top 5 Data Science Certifications
 
Different Roles in Machine Learning Career
Different Roles in Machine Learning CareerDifferent Roles in Machine Learning Career
Different Roles in Machine Learning Career
 

Recently uploaded

How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 

Python Closures Explained | What are Closures in Python | Python Closures

  • 1. Copyright Intellipaat. All rights reserved. Closures in Python
  • 2. Copyright Intellipaat. All rights reserved. Agenda 03 Example 01 Prerequisite 04 Use case 02 Definition
  • 3. Copyright Intellipaat. All rights reserved. Prerequisite
  • 4. Copyright Intellipaat. All rights reserved. Prerequisite First class function First class functions allows us to treat functions as any other objects, so that we can use them to:  pass as an argument to another function  return the function from another function  assign the function to another variable Nested function Python supports the concept of a "nested function" or "inner function", which is simply a function defined inside another function. Note: Not to be confused with recursive functions
  • 5. Copyright Intellipaat. All rights reserved. Definition
  • 6. Copyright Intellipaat. All rights reserved. Definition Closure is an inner function that remembers and has access to the variables in the local scope in which it was created even after the outer function has finished executing. A closure closes over their free variable from their environment
  • 7. Copyright Intellipaat. All rights reserved. Example
  • 8. Copyright Intellipaat. All rights reserved. Use case
  • 9. Copyright Intellipaat. All rights reserved. Use case  To replace the unnecessary use of class: Suppose you have a class that contains just one method besides the __init__ method. In such cases, it is better to use a closure instead of a class.  To avoid the use of the global scope: If you have global variables which only one function in your program will use, think closure. Define the variables in the outer function and use them in the inner function.  To implement data hiding: The only way to access the enclosed function is by calling the enclosing function. There is no way to access the inner function directly.  To remember a function environment even after it completes its execution: You can then access the variables of this environment later in your program.
  • 10. Copyright Intellipaat. All rights reserved. • Further Learning..
  • 11. Copyright Intellipaat. All rights reserved. Further Learning
  • 12. Copyright Intellipaat. All rights reserved. India: +91-7022374614 US: 1-800-216-8930 (TOLL FREE) support@intellipaat.com 24/7 Chat with Our Course Advisor

Editor's Notes

  1. Thank you!