Forum Archive

Immutable, Immutable! Don’t need no stinkin’....

adrius42

I have tried searching the manual for a simple action...

I want to store variables in an array, I found and implemented many ways of doing this
Creating the array
variablesarray=[]
Creating the first elements is easy with variablesarray.append(list)

I can even read them back with variablesarray[x][y]

But I cannot for the life of me figure out how to change an element in the array

In my old basic world it was very simple variablesarray[x][y]=newvalue

How can I achieve this simple variable change in Python, what am I missing.

I am confident it will be something simple... but I have yet to discover it.

Pointers gratefully received...

JonB
a=[[1,2,3],[4,5,6],[7,8,9]]
print(a)
print('a[0]append')
a[0].append(4)
print(a)
print('a[0].extend [0]')
a[0].extend([5,6])
print(a)
print('a[0][0]=99')
a[0][0]=99
print(a)
print('del(a[0][1])')
del(a[0][1])
print(a)
print('a[0].insert(1,2)')
a[0].insert(1,2)
print(a)

Are you getting an error of some sort? Maybe post the code that was failing. lists in python are generally mutable.

mikael

@adrius42, just making sure you are not appending or overriding list, which is a built-in.