Basic Lists and Loops Methods in Python Language.
A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Just as strings are defined as characters between quotes, lists are defined by having values between square brackets [ ].
Looping means repeating something over and over until a particular condition is satisfied.
There are mainly two types of loops. Let’s discuss them one by one.
A for loop in Python is used to iterate over a sequence (list, tuple, set, dictionary, and string).
Fig: Flowchart of a for loop
for iterating_var in sequence:
statement(s)
Fig: for loop example
The preceding code executes as follows: The variable i is a placeholder for every item in your iterable object. The loop iterates as many times as the number of elements and prints the elements serially.
The while loop is used to execute a set of statements as long as a condition is true.
Fig: While loop flowchart
while expression:
statements
Fig: While loop
The preceding code executes as follows: We assign the value to variable x as 1. Until the value of x is less than 3, the loop continues and prints the numbers.
Ref: https://www.simplilearn.com/tutorials/python-tutorial/python-loops