I have gone through the Loops section of the Python 3 course, but I am still stumped by loops.
For example, why when you loop through a list and print the elements of that list, does Python print the elements but they are no longer in a list structure?
Here is the link to the exercise:
This is what the code looks like:
dog_breeds = ['french_bulldog', 'dalmatian', 'shihtzu', 'poodle', 'collie'] for breed in dog_breeds: print(breed)
Also, why do you sometimes define a variable outside of the for loop to later use within the for loop, but other times you need to define a variable within the for loop?
For example, if I wanted to alter a list, why would the code need to look like this:
my_list = [ "cats and dogs", "frogs and toads"] empty_list =  #add a 1 to each element in my_list for phrases in my_list: new_list = phrases + 1 empty_list.append(new_list) return empty_list
Why couldn’t the code just alter my_list using the empty_list variable defined outside of the for loop instead of also defining another variable (new_list) in the for loop?