I want to use Python to create a file that looks like
# empty in the first line
this is the second line
this is the third line
I tried to write this script
myParagraph = []
myParagraph[0] = ''
myParagraph[1] = 'this is the second line'
myParagraph[2] = 'this is the third line'
An error is thrown: IndexError: list index out of range
. There are many answers on similar questions that recommend using myParagraph.append('something')
, which I know works. But I want to better understand the initialization of Python lists. How to manipulate a specific elements in a list that's not populated yet?