4-1 Working with For-Loop (syntex)
python Looping through an entire List when you want to do the same action with every item in a list, you can use Python’s for loop. Let’s say we have a list of magician’s names and we want to print out each name in the list. This loop system approach could cause several problems for one, it would be repetitive to do this with a long list of names. Also we’d have to change our code each time the list’s length changed. A for loop avoids both of these issues by letting Python manage these issues internally. Let’s use a for loop to print out each name in a list of magicians : magicians = [ 'alice' , 'david' , 'carolina' ] for magician in magicians : print ( magician ) The output is a simple printout of each name in the list : alice david carolina A closer look at looping One of the most common ways to automates repetitive tasks. For example : for magician in magicians : This line tells Python to retrieve the first valu