|
for x in list:
>>>x = "non"
Each time through the loop, x just points to the same thing as a position in the list, and later x points to "non". The original position in the list still points to the original object, and the list has always been used as an rvalue.
Can be understood in C:
const char* list[] = {"apple9927", "jason"};
const char* x;
int i;
for(int i=0; i<2; i++)
{
x = list[i];
x = "non";
}
There is no operation to modify the list (list is not used as an lvalue);
You can use the index if you want to modify the list:
w = ["int", "str"]
for i in range(len(w)):
w[i] = "none"
print w |
|