Roshan Book

My Tech Notebook

Python tutorial 9–iterators and controlling loops

getting through data, one by one and doing something with it

For loop is designed to work with iterators

for line in fh.readlines():

print(line, end=’’)

In python all the container types are iterators

Common iterators

‘string’ – container that containers individual characters


Enumerating Iterators

for index,line in enumerate(fh.readliness()):

if c—‘s’  : print(‘index{} iis an s’.format(i))

# Controlling the loop through break and continue

Break – terminate the loop and come out of it

Continue – break one cycle of loop and continue from next loop


if c==’s’  : break/continues

# For else- code which runs once for loop is over. it also works as while else

for c in s:

            print (c,end=’’)


            print (‘else’)


4 responses to “Python tutorial 9–iterators and controlling loops

  1. Delena Adolphson October 17, 2011 at 7:27 am

    nice work, continue the great blog.

  2. Louis Vuitton handbags on sale December 5, 2011 at 4:25 am

    That is definitely fascinating, You’re an overly professional blogger. I’ve joined your rss feed and stay up for in the hunt for more of your excellent post.

  3. Louis Vuitton wallets Sale December 6, 2011 at 4:56 am

    wonderful publish, really informative. I wonder why the opposite experts of this sector do not notice this. You should continue your writing. I’m confident, you have a superb readers’ base already!

  4. cheap Moncler December 18, 2011 at 1:49 am

    I get a presentation thursday, i will in the check out similarly info.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: