General

Advanced Python

General May 17, 2019
Advanced Python

Advanced Python

Python Iterators

As a python is an object-oriented programming language and iterators also considered an object that is used to Travers or iterates over the object which can hold some data and we need that data in looping order then iterators are the object which can do this job for python programmer.

Iterator object has methods like:

  • next
  • iter

Iterators are mostly helping us to iterate the data containers like List, Dictionary, set.

The basic way of traversing in data objects is for loop and internally for loop also uses iterators so indirectly we use iterators only in the hidden way.

We can also create our own iterators on Python.

 Python Generators

As we have discussed iterators in the previous topic that we can create the iterators in python to design iterators we need to implement two methods next and iter.

The creating iterators are considered more complex than comparing to using generators in python, yes we can use generators function instead of creating iterators.

To use the generator functions we have to understand two keywords in python.

Return

It is used to return the final value from a python function

Yield

It is required when after returning one value you want to proceed function further for execution meaning return statement terminate function but yield continue after that also.

To create generators functions we can use yield and return statements.

def example_gen():
n = 1
print('first')
yield n
n += 1
print('second')
yield n
n += 1
print('end')
yield n
for item in example_gen():
print(item)

Python Decorators

Decorators are the special feature of python that gives a facility to add the extra functionality to an existing function or a part of a code.

Decorators are used to implementing the met programming concept in python.

To understand the decorators it’s necessary that we should know almost everything in python basics like function as an object, parameter passing in python function and classes also.

Simple example decorators:

def some_function(parameter):
 """ here is the function body"""
print("this is some_function " + parameter)
some_function("callsing some function ")
a = some_function
# here we can pass a as
a("calling a")

 Python Closure.

  Python closure is the function that remembers the enclosing scopes inspite of absence in memory.

As we have discussed the decorators before so it’s easy to understand the closure in python. Because it is mention in decorators that to understand the decorators we need every basic of python including classes.

To understand the decorators we need to understand closures also.

So now coming to the point is what closure in python is.

Python provides the nesting of the functions, nesting of the functions is nothing but function inside functions.

Example:

def outer_function(msg):
def inner_function()
print(msg)       
inner_function()

Advantages of closure:

  • We can avoid the use of global variable.
  • Closure provides the mechanism of data hiding.
  • When one method is required to implement in most of the cases the closure will be the best choice for python programmers.
  • When we use decorators then closures provides a lot more features to achieve the task with decorators.

Click Here-> Get Python Training with Real-time Projects

Besant Technologies – Chennai & Bangalore Branch Locations

Besant Technologies - Velachery Branch

Plot No. 119, No.8, 11th Main road, Vijaya nagar,

Velachery, Chennai - 600 042

Tamil Nadu, India

Landmark - Reliance Digital Opposite Street

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Tambaram Branch

No.2A, 1st Floor, Duraisami Reddy Street,

West Tambaram, Chennai - 600 045

Tamil Nadu, India

Landmark - Near By Passport Seva

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - OMR Branch

No. 5/318, 2nd Floor, Sri Sowdeswari Nagar,

OMR, Okkiyam Thoraipakkam, Chennai - 600 097

Tamil Nadu, India

Landmark - Behind Okkiyampet Bus Stop,

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Porur Branch

No. 180/84, 1st Floor, Karnataka Bank Building,

Trunk Road, Porur, Chennai - 600 116

Tamil Nadu, India

Landmark - Opposite to Gopalakrishna Theatre

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Anna Nagar Branch

Plot No:1371, 28th street kambar colony,

I Block, Anna Nagar, Chennai - 600 040

Tamil Nadu, India

Landmark - Behind Reliance Fresh

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - T.Nagar Branch

Old No:146/2- New No: 48,

Habibullah Road,T.Nagar, Chennai - 600 017

Tamil Nadu, India

Landmark - Opposite to SGS Sabha

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Thiruvanmiyur Branch

22/67, 1st Floor, North mada street, Kamaraj Nagar

Thiruvanmiyur, Chennai 600041

Tamil Nadu, India

Landmark - Above Thiruvanmiyur ICICI Bank

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Siruseri Branch

No. 4/76, Ambedkar Street, OMR Road, Egatoor, Navallur,

Siruseri, Chennai 600130

Tamil Nadu, India

Landmark - Near Navallur Toll Gate, Next to Yamaha Showroom

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Maraimalai Nagar Branch

No.37, Ground Floor, Thiruvalluvar Salai,

Maraimalai Nagar,Chennai 603209

Tamil Nadu, India

Landmark - Near to Maraimalai Nagar Arch

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - BTM Layout Branch

No 2, Ground floor, 29th Main Road,

Kuvempu Nagar,BTM Layout 2nd Coming from Silkboard,

AXA company signal, Stage, Bangalore - 560 076

Karnataka, India

Landmark - Next to OI Play School

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Marathahalli Branch

No. 43/2, 2nd Floor, VMR Arcade,

Varthur Main Road, Silver Springs Layout,

Munnekollal, Marathahalli, Bengaluru - 560037

Karnataka, India

Landmark - Near Kundalahalli Gate Signal

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Rajaji Nagar Branch

No. 309/43, JRS Ecstasy, First Floor,

59th Cross, 3rd Block, Bashyam Circle,

Rajaji Nagar, Bangalore - 560 010

Karnataka, India

Landmark - Near Bashyam Circle

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Jaya Nagar Branch

No. 2nd Floor,1575,11th Main Road,

4th T-Block, Pattabhirama Nagar,

Jaya Nagar, Bangalore - 560 041

Karnataka, India

Landmark - Opposite to Shanthi Nursing Home

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Kalyan Nagar Branch

No.513, 4th Cross Rd

2nd Block, HRBR Layout,

Kalyan Nagar, Bangalore - 560 043

Karnataka, India

Landmark - Opposite to kalayan nagar Axis Bank

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Electronic City Branch

No. 7, 3rd Floor, Ganga Enclave,

Neeladri Road, Karuna Nagar, Doddathoguru Village,

Electronics City Phase 1, Electronic City,

Bangalore - 560100, karnataka, India

Landmark - Adjacent to HDFC Bank and State Bank Of India

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Indira Nagar Branch

No.54, 1st Floor,

5th Main kodihalli,

Bengaluru, Karnataka 560008, India

Landmark - Behind Leela Palace Hotel,

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - HSR Layout Branch

Plot No. 2799 & 2800, 27th Main,

1st Sector, HSR Layout,

Bengaluru, Karnataka 560102, India

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Hebbal Branch

No.29, 2nd Floor, SN Complex,

14th Main Road, E-Block Extention, Sahakara Nagar,

Bengaluru, Karnataka -560092, India

  +91-8767 260 270

  info@besanttechnologies.com

Scroll Up