Untitled Document
Closures
1. Introduction Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Introduction 
    
       
       
2. Simple Example of Closures . Click Here
#********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
# Simple Example of Closures .

def outer_func():
	message = 'Hi'

	def inner_func():
		print(message)

	return inner_func()

outer_func()       

       
3. Practical Examples Of Closures Click Here
#********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
# Practical Examples Of Closures 

def outer_func(msg):
	message = msg

	def inner_func():
		print(message)

	return inner_func

hi_func = outer_func('Hi')
hello_func = outer_func('Hello')

hi_func()
hello_func()      

            
4. Some More Practical Example Click Here
#********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
# Some More Practical Example  

import logging
logging.basicConfig(filename='example.log', level=logging.INFO)

def logger(func):
	def log_func(*args):
		logging.info('Runnig "{}" with arguments {}'.format(func.__name__, args))
		print(func(*args))
	return log_func

def add(x, y):
	return x+y

def sub(x,y):
	return x-y

add_logger = logger(add)
sub_logger = logger(sub)

add_logger(3, 3)
add_logger(4, 5)

sub_logger(6, 3)
sub_logger(5, 4)
            
Untitled Document