list storing variables
Marko Rauhamaa
marko at pacujo.net
Mon Feb 23 13:22:31 EST 2015
Peter Pearson <pkpearson at nowhere.invalid>:
>>>>> a = 2; b = 5
>>>>> Li = [a, b]
>>>>> Li
>> [2, 5]
>>>>> a=3
>>>>> Li
>> [2, 5]
>
> [...]
>
> The word "variable" brings implications and assumptions that get
> people into trouble in Python. Python doesn't have variables.
> It has objects, and you can assign names to objects -- like sticky
> notes, as someone in this newsgroup helpfully pointed out long ago.
>
> This way of thinking is significantly different from the familiar
> "variable" mind-set of C, but looks similar enough to produce some
> confusion. For me, the sticky-note analogy helped a lot, and in a
> few days many things made more sense.
It's no different in C:
#include <stdio.h>
int main()
{
int a = 2, b = 5;
int Li[2] = { a, b };
printf("%d %d\n", Li[0], Li[1]);
a = 3;
printf("%d %d\n", Li[0], Li[1]);
return 0;
}
Outputs:
2 5
2 5
Marko
More information about the Python-list
mailing list