♦ Python For Loop
♣ About Python For Loop
A For Loop in Python is used to iterate over an iterable sequence, i.e either a list, tuple, dictionary, a set, string or any custom (Class Induced) iterative object.Basic Syntax
for object in sequence: //code block
Syntax Explanation:
sequence: sequence of objects(can be of any Data Types) object: single object while iterating //code block: program written to execute for objects
♣ Example1: Loop Through a Python List
In this example, Looping through a list is represented. Example
Input:
Output:
♣ Example2: Looping Through a Python String
In this example, Looping through a string is represented. Example
Input:
Output:
♣ Example3: "Break" in For-Loop in Python
In this example, Break statement is illustrated. Example
Input:
Output:
♣ Example4: "Continue" in For-Loop in Python
In this example, Continue statement is illustrated. Example
Input:
Output: