With all these explanations I decided to mess around and write what I learned to this forum. Hopefully this helps someone in the future.
students_period_A = [“Alex”, “Briana”, “Cheri”, “Daniele”]
students_period_B = [“Dora”, “Minerva”, “Alexa”, “Obie”]
for student in students_period_A:
students_period_B.append(student)
print(students_period_B)
Because this is a “for” loop, what we end up with is the program appending a single element from “student” (which is equal to “students_period_A”), to “students_period_B” and printing out the new list every single time it does the loop, until list “students_period_A” has no more elements to append to list “students_period_B”.
Our output would be:
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’]
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’]
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’, ‘Cheri’]
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’, ‘Cheri’, ‘Daniele’]
students_period_A = [“Alex”, “Briana”, “Cheri”, “Daniele”]
students_period_B = [“Dora”, “Minerva”, “Alexa”, “Obie”]
for student in students_period_A:
print(students_period_B + students_period_A)
Exercising this code will add list “students_period_B” to list “students_period_A” for every element in list “students_period_A” so we will get 4 identical outputs:
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’, ‘Cheri’, ‘Daniele’]
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’, ‘Cheri’, ‘Daniele’]
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’, ‘Cheri’, ‘Daniele’]
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’, ‘Cheri’, ‘Daniele’]
students_period_A = [“Alex”, “Briana”, “Cheri”, “Daniele”]
students_period_B = [“Dora”, “Minerva”, “Alexa”, “Obie”]
for student in range(1):
print(students_period_B + students_period_A)
This code will add list “students_period_B” to list “students_period_A” as a single loop since our range() is only 1.
Our output would be:
[‘Dora’, ‘Minerva’, ‘Alexa’, ‘Obie’, ‘Alex’, ‘Briana’, ‘Cheri’, ‘Daniele’]