Copy the following code on the left in your IDE to execute the process shown in the image on the right.
For Loop
In this example, the code iterates through the notable_tulane_alumni variable and prints the length of each name. The "name" variable acts as a proxy for each individual name to be passed through the for loop.
notable_tulane_alumni = ["Victoria Reggie Kennedy",
"Paul Michael Glaser",
"Jerry Springer"] Jupyter Notebook View
for name in notable_tulane_alumni:
print (len(name))
For Loop with a Function
This examples shows a similar process, but instead of printing out each name length, the code stores each value in a new list variable (name_count). This variable is printed at the end of the code. The .append method is used to update the new list variable.
notable_tulane_alumni = ["Victoria Reggie Kennedy",
"Paul Michael Glaser",
"Jerry Springer"] Jupyter Notebook View
name_count = []
for name in notable_tulane_alumni:
name_count.append(len(name))
print (name_count)