Python List Append vs Extend

preview_player
Показать описание


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.

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.

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.





#PythonMarathon #LearnPython #PythonTutorial
Рекомендации по теме
Комментарии
Автор

I love these two methods. I start most of my lessons with append. Nice video :)

PythonBasics