r/learnpython • • 12d 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

5

u/ToshiAbashi 12d ago

The others have answered the question, but I just wanna add. The best thing you can do for yourself as you’re learning when these never ending questions arise for you, get comfortable navigating the documentation.

It’s a headache I know and it’s an overwhelming amount of knowledge nobody can memorise all of. But you will often find yourself asking a specific question like this, where you can just have a browse of the thing you’re working with even if you don’t know the name of the answer.

So in this case scrolling through the methods for lists, which in python that’s what you’re calling an array, you will find the thing related to the action you’re trying to take. Sometimes you’ll find a simpler way of doing something than you initially thought.

The trick long-term isn’t how much you can memorise, but how effectively you can find what you need for the current solution.

1

u/LayotFctor 12d ago

Also install an LSP in your IDE. If I type a dot after my list variable, append is suggested among a whole list of applicable methods. Sometimes, it even prints method documentation and examples too.