What’s the equivalent of PHP’s “append to array” ($my_array[] = "abc";) in Python, which I have recently started learning?
Let’s say that I’ve a dictionary like this:
my_dict = {'fruits':['orange', 'pear']}
And now I want to add another fruit to my_dict['fruits']: apple
Python is great for experimenting and helping you find things like this, and as you already know roughly what you’re looking for (just named/termed differently), then here’s a tip that should make it a bit easier for you…
So we know that it’s list (in this case the built-in list type)… We know we want to “add” something to it… So let’s look at what it offers…
insert,extendandappendlook useful… Let’s see what it says…Doesn’t sound quite right…
Seems a little specific about positioning…
Hey, looking good 🙂
It just so happens that in this instance, you could just do
help(my_dict['fruits'])…