Untitled Document
Functions
1. Intoduction to Variable Scope Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****  
       # Intoduction to Variable Scope    
       # In this chapter we will scope of variables in Python 
       # whenever we declare any variable it has its own scope based on which location it has been declared  - variable 
       # Python uses following Scope approach - LEGB - Local, Enclosing , Global and Builtin 
       # We will see scope of variables by examples
      
       
2. Simple Example to show global and local scope of variable Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Simple Example to show global and local scope of variable
       
       x ='global x'
       def test():
       	x ='local x'
       	print(x)
       test()
       print(x)
       
3. Simple Example to show use of global keyword Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Simple Example to show use of global keyword
       
       x ='global x'
       def test():
       	global x
       	x ='local x'
       	print(x)
       
       test()
       print(x)
       
4. Builtin Method error Example Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Builtin Method error Example
       
       #Simple Example to show builtin function error ; the below code will error as we have tried to overwrite the
       # Builtin min function with out local min function ; since our local builtin function is not taking arguments but
       # we did pass the list hence it will throw error
       
       def min():
       	pass
       
       print(min([1, 5, 3, 2]))
       
5. Enclosing variable Example - nonlocal keywordClick Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Enclosing variable Example - nonlocal keyword
       
       def outer():
       	x = 'outer x'
       	def inner():
       		nonlocal x
       		x = 'inner x'
       		print(x)
       	inner()
       	print(x)
       outer()
       
       
Untitled Document