How does Python access the items in the list?


#1

How does Python know what to access in “for student in students” loop if the “student” variable hasn’t been defined?


What is Codecademy checking for to be printed?
#2
students = [blah, blahh, blahhh]
def function(list):
  for student in students: # will run loop for blah, then blahh, then blahhh and assign the neccesary variable

The for student is you clairifying a new variable to attach whatever
happens inside of the students list


#3

student is a local variable (function scope) defined in the for loop. The loop is a readonly, lookup operation that goes through each item in the list, in turn. The order is not important.

students = [lloyd, alice, tyler]

for student in students:

student will be one object reference (dictionary) at a time, going through the entire list. These references are then passed to a function that can unpack the object attributes.


#4

Left the part out that it stays within the function. Better said then I. :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.