Python List Append vs Extend

Pubblicato il: 24 luglio 2019
sul canale di: Python Marathon
301
7

Descargar el Código: patreon.com/pythonmaraton

Join Patreon: patreon.com/pythonmaraton
^Downloadable code & more! In this video we will answer the popular stack overflow question: What is the difference between Python’s list methods append and extend. https://stackoverflow.com/questions/2...

So let’s open ipython and do a quick list comprehension to create a list x.

And now let’s also create a list y.

Now the append function let’s you add a new object to a list. So we can add another int object to x by doing np.append with the number 100. Now you’ll see x is the same but with a 100 appended to the end.

With y we will do the same thing.

Now the .extend method is a bit different. Instead of adding on objects you use it to add on another iterable. In other words, you can use it to connect two lists together.

So x.extend(y). It does this in place. Now x is has ALL of y’s entries appended to it.

Let’s print that out so you can see it better. Now x is both x and y combined. So that is the difference. append lets you add one values and extend lets you add on lists.

So there you have it that is the difference between python’s list methods append and extend.

Please check out some of my other python videos and please subscribe for more python content :D
This is a Python anaconda tutorial for help with coding, programming, or computer science. These are short python videos dedicated to troubleshooting python problems and learning Python syntax. For more videos see Python Help playlist by Rylan Fowers.

✅Subscribe: https://www.youtube.com/channel/UCub4...

📺Channel: https://www.youtube.com/channel/UCub4...

▶️Watch Latest Python Content: https://www.youtube.com/watch?v=myCPg...

▶️Watch Latest Other Content: https://www.youtube.com/watch?v=2YfQs...



🎵Theme Music: https://www.bensound.com/royalty-free...



#PythonMarathon #LearnPython #PythonTutorial


In questa pagina del sito puoi guardare il video online Python List Append vs Extend della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Python Marathon 24 luglio 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 301 volte e gli è piaciuto 7 spettatori. Buona visione!