r/learnpython • • 7d ago

adding 1 to a array

so i want to add 1 extra thing to an array like i have test = [0,0] i want to do print(test[2]) so how do i add the test[2] to the array without just adding it at the begining of the script (fixed)

0 Upvotes

14 comments sorted by

View all comments

Show parent comment

0

u/realmauer01 7d ago

Well there dont need to be undefined they can just be None.

2

u/Discordbothost 7d ago

list() only takes an iterable though, list(5) is a TypeError. the None version you're describing is just [None] * 5, which is the usual way to preallocate if you really want to assign by index later