-2

I have the following code:

myList = ['A','B','C']
for letter in myList:
    letter = myList

When running it I would expect variables to be assigned as following:

A = ['A', 'B', 'C'] 
B = ['A', 'B', 'C'] 
C = ['A', 'B', 'C']

Instead it seems that the loop is only assigning values to the "myList" component of the loop and forgetting to assign the anything for "letter". Hence the actual variable assignment looks like this:

letter = ['A', 'B', 'C']

Can someone please explain to me why python does not replace "letter" with values from "myList"?

Thank you!

user2182066
  • 157
  • 2
  • 9

1 Answers1

0

It DOES replace "letter" with values from "myList": it put the value in the variable letter.

What it doesn't do is assign those values to a variable whose name is contained in letter, because that's not how assignment works

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101