Python Tutorial
What is Python ??
Python Get Started
Python Syntax
Python Variables and Types
Python Data Types
Python Operators
Python Input and Output
Python If ... Else
Python While Loops
Python For Loops
Python Strings
Python Functions
Python Lambda Function
Author Profile Altaf Shaikh
Altaf Shaikh


Python For Loops

January 17th 2020

Python For Loops
Python For Loops

Python For Loops





Note:  The for loop does not require an indexing variable to set beforehand.

The range() function

  • It is type of iterator
  • Creates a list containing arithematic progression


range(start, stop)
range(start, stop, step)

Note: Loops will stop one position before the stop value

Note: Step is the amount of increments per iteration


String Traversal 

Even strings are iterable objects, they contain a sequence of characters.


The break Statement

With the break statement we can stop the loop before it has looped through all the items.


The continue Statement

With the continue statement we can stop the current iteration of the loop, and continue with the next.


Nested Loops

A nested loop is a loop inside a loop.

The "inner loop" will be executed one time for each iteration of the "outer loop".


The pass Statement

for loops cannot be empty, but if you for some reason have a for loop with no content, put in the pass statement to avoid getting an error.