Python : How to run for loop fixed number of time

Objective : Regular for loop iterates through all items in list, how can one effectively run the for loop limited number of time, (if he know in advance the number or iteration required)

list = [1,2,3,4,5,6]

This will run for loop only 3 times to print first 3 items

>> for item in list [ 0:3] :

This will run for loop from 3rd item to end of list

>> for item in list [ 2:len(list)-1] :

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s