Python List Append vs Extend

Veröffentlicht am: 24 Juli 2019
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video Python List Append vs Extend mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Python Marathon 24 Juli 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 301 Mal angesehen und es wurde von 7 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!