'IndexError: list assignment index out of range - python list

I am trying to assign values to a list at ith position.

coords = [] 

lat = 37.312312
long = -118.31231

coords[0] = lat
coords[1] = long

IndexError                                Traceback (most recent call last)
/var/folders/d0/gnksqzwn2fn46fjgrkp6045c0000gn/T/ipykernel_56868/3062929082.py in <module>
      4 long = -118.31231
      5 
----> 6 coords[0] = lat
      7 coords[1] = long

IndexError: list assignment index out of range


Solution 1:[1]

I mean, you could do this if you REALLY don’t want to use append:

coords = [0,0] 

lat = 37.312312
long = -118.31231

coords[0] = lat
coords[1] = long

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pwuurple