Set the index of a Python array -
i'm trying set index of array in python, isn't acting expected:
thething = [] thething[0] = 0 '''set thething[0] 0'''
this produces following error:
traceback (most recent call last): file "prog.py", line 2, in <module> thething[0] = 0; indexerror: list assignment index out of range
what correct syntax setting index of array in python?
python lists don't have fixed size . set 0
th element, need have 0
th element:
>>> thething = [] >>> thething.append(12) >>> thething [12] >>> thething[0] = 0 >>> thething [0]
javascript's array object works bit differently python's, fills in previous values you:
> x [] > x[3] = 5 5 > x [undefined × 3, 5]
Comments
Post a Comment